?

Average Error: 38.6 → 31.7
Time: 9.8s
Precision: binary64
Cost: 7836

?

\[0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)} \]
\[\begin{array}{l} t_0 := im \cdot \sqrt{\frac{-1}{re}}\\ t_1 := 0.5 \cdot t_0\\ t_2 := 0.5 \cdot \sqrt{2 \cdot \left(\left(-im\right) + re\right)}\\ \mathbf{if}\;re \leq -2.35 \cdot 10^{+136}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;re \leq -4.4 \cdot 10^{-15}:\\ \;\;\;\;\frac{t_0}{-2}\\ \mathbf{elif}\;re \leq -1.08 \cdot 10^{-97}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;re \leq -8.6 \cdot 10^{-276}:\\ \;\;\;\;0.5 \cdot \sqrt{im \cdot 2}\\ \mathbf{elif}\;re \leq 10^{-224}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;re \leq 2 \cdot 10^{-166}:\\ \;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(re + im\right)}\\ \mathbf{elif}\;re \leq 6.2 \cdot 10^{-102}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \left(2 \cdot \sqrt{re}\right)\\ \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 (* im (sqrt (/ -1.0 re))))
        (t_1 (* 0.5 t_0))
        (t_2 (* 0.5 (sqrt (* 2.0 (+ (- im) re))))))
   (if (<= re -2.35e+136)
     t_1
     (if (<= re -4.4e-15)
       (/ t_0 -2.0)
       (if (<= re -1.08e-97)
         t_1
         (if (<= re -8.6e-276)
           (* 0.5 (sqrt (* im 2.0)))
           (if (<= re 1e-224)
             t_2
             (if (<= re 2e-166)
               (* 0.5 (sqrt (* 2.0 (+ re im))))
               (if (<= re 6.2e-102) t_2 (* 0.5 (* 2.0 (sqrt re))))))))))))
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 = im * sqrt((-1.0 / re));
	double t_1 = 0.5 * t_0;
	double t_2 = 0.5 * sqrt((2.0 * (-im + re)));
	double tmp;
	if (re <= -2.35e+136) {
		tmp = t_1;
	} else if (re <= -4.4e-15) {
		tmp = t_0 / -2.0;
	} else if (re <= -1.08e-97) {
		tmp = t_1;
	} else if (re <= -8.6e-276) {
		tmp = 0.5 * sqrt((im * 2.0));
	} else if (re <= 1e-224) {
		tmp = t_2;
	} else if (re <= 2e-166) {
		tmp = 0.5 * sqrt((2.0 * (re + im)));
	} else if (re <= 6.2e-102) {
		tmp = t_2;
	} else {
		tmp = 0.5 * (2.0 * sqrt(re));
	}
	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 = im * sqrt(((-1.0d0) / re))
    t_1 = 0.5d0 * t_0
    t_2 = 0.5d0 * sqrt((2.0d0 * (-im + re)))
    if (re <= (-2.35d+136)) then
        tmp = t_1
    else if (re <= (-4.4d-15)) then
        tmp = t_0 / (-2.0d0)
    else if (re <= (-1.08d-97)) then
        tmp = t_1
    else if (re <= (-8.6d-276)) then
        tmp = 0.5d0 * sqrt((im * 2.0d0))
    else if (re <= 1d-224) then
        tmp = t_2
    else if (re <= 2d-166) then
        tmp = 0.5d0 * sqrt((2.0d0 * (re + im)))
    else if (re <= 6.2d-102) then
        tmp = t_2
    else
        tmp = 0.5d0 * (2.0d0 * sqrt(re))
    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 = im * Math.sqrt((-1.0 / re));
	double t_1 = 0.5 * t_0;
	double t_2 = 0.5 * Math.sqrt((2.0 * (-im + re)));
	double tmp;
	if (re <= -2.35e+136) {
		tmp = t_1;
	} else if (re <= -4.4e-15) {
		tmp = t_0 / -2.0;
	} else if (re <= -1.08e-97) {
		tmp = t_1;
	} else if (re <= -8.6e-276) {
		tmp = 0.5 * Math.sqrt((im * 2.0));
	} else if (re <= 1e-224) {
		tmp = t_2;
	} else if (re <= 2e-166) {
		tmp = 0.5 * Math.sqrt((2.0 * (re + im)));
	} else if (re <= 6.2e-102) {
		tmp = t_2;
	} else {
		tmp = 0.5 * (2.0 * Math.sqrt(re));
	}
	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 = im * math.sqrt((-1.0 / re))
	t_1 = 0.5 * t_0
	t_2 = 0.5 * math.sqrt((2.0 * (-im + re)))
	tmp = 0
	if re <= -2.35e+136:
		tmp = t_1
	elif re <= -4.4e-15:
		tmp = t_0 / -2.0
	elif re <= -1.08e-97:
		tmp = t_1
	elif re <= -8.6e-276:
		tmp = 0.5 * math.sqrt((im * 2.0))
	elif re <= 1e-224:
		tmp = t_2
	elif re <= 2e-166:
		tmp = 0.5 * math.sqrt((2.0 * (re + im)))
	elif re <= 6.2e-102:
		tmp = t_2
	else:
		tmp = 0.5 * (2.0 * math.sqrt(re))
	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(im * sqrt(Float64(-1.0 / re)))
	t_1 = Float64(0.5 * t_0)
	t_2 = Float64(0.5 * sqrt(Float64(2.0 * Float64(Float64(-im) + re))))
	tmp = 0.0
	if (re <= -2.35e+136)
		tmp = t_1;
	elseif (re <= -4.4e-15)
		tmp = Float64(t_0 / -2.0);
	elseif (re <= -1.08e-97)
		tmp = t_1;
	elseif (re <= -8.6e-276)
		tmp = Float64(0.5 * sqrt(Float64(im * 2.0)));
	elseif (re <= 1e-224)
		tmp = t_2;
	elseif (re <= 2e-166)
		tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(re + im))));
	elseif (re <= 6.2e-102)
		tmp = t_2;
	else
		tmp = Float64(0.5 * Float64(2.0 * sqrt(re)));
	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 = im * sqrt((-1.0 / re));
	t_1 = 0.5 * t_0;
	t_2 = 0.5 * sqrt((2.0 * (-im + re)));
	tmp = 0.0;
	if (re <= -2.35e+136)
		tmp = t_1;
	elseif (re <= -4.4e-15)
		tmp = t_0 / -2.0;
	elseif (re <= -1.08e-97)
		tmp = t_1;
	elseif (re <= -8.6e-276)
		tmp = 0.5 * sqrt((im * 2.0));
	elseif (re <= 1e-224)
		tmp = t_2;
	elseif (re <= 2e-166)
		tmp = 0.5 * sqrt((2.0 * (re + im)));
	elseif (re <= 6.2e-102)
		tmp = t_2;
	else
		tmp = 0.5 * (2.0 * sqrt(re));
	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[(im * N[Sqrt[N[(-1.0 / re), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(0.5 * t$95$0), $MachinePrecision]}, Block[{t$95$2 = N[(0.5 * N[Sqrt[N[(2.0 * N[((-im) + re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[re, -2.35e+136], t$95$1, If[LessEqual[re, -4.4e-15], N[(t$95$0 / -2.0), $MachinePrecision], If[LessEqual[re, -1.08e-97], t$95$1, If[LessEqual[re, -8.6e-276], N[(0.5 * N[Sqrt[N[(im * 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 1e-224], t$95$2, If[LessEqual[re, 2e-166], N[(0.5 * N[Sqrt[N[(2.0 * N[(re + im), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 6.2e-102], t$95$2, N[(0.5 * N[(2.0 * N[Sqrt[re], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]]]]]]
0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}
\begin{array}{l}
t_0 := im \cdot \sqrt{\frac{-1}{re}}\\
t_1 := 0.5 \cdot t_0\\
t_2 := 0.5 \cdot \sqrt{2 \cdot \left(\left(-im\right) + re\right)}\\
\mathbf{if}\;re \leq -2.35 \cdot 10^{+136}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;re \leq -4.4 \cdot 10^{-15}:\\
\;\;\;\;\frac{t_0}{-2}\\

\mathbf{elif}\;re \leq -1.08 \cdot 10^{-97}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;re \leq -8.6 \cdot 10^{-276}:\\
\;\;\;\;0.5 \cdot \sqrt{im \cdot 2}\\

\mathbf{elif}\;re \leq 10^{-224}:\\
\;\;\;\;t_2\\

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

\mathbf{elif}\;re \leq 6.2 \cdot 10^{-102}:\\
\;\;\;\;t_2\\

\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(2 \cdot \sqrt{re}\right)\\


\end{array}

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original38.6
Target33.3
Herbie31.7
\[\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 6 regimes
  2. if re < -2.35000000000000002e136 or -4.39999999999999971e-15 < re < -1.0799999999999999e-97

    1. Initial program 55.6

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

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

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

      [Start]38.3

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

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

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

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

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

      [Start]64.0

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

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

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

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

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

      rational.json-simplify-43 [=>]64.0

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

      exponential.json-simplify-20 [=>]36.3

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

      rational.json-simplify-8 [<=]36.3

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

      rational.json-simplify-10 [=>]36.3

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

      rational.json-simplify-35 [=>]36.3

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

      metadata-eval [=>]36.3

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

      rational.json-simplify-46 [<=]36.3

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

      rational.json-simplify-8 [<=]36.3

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

      rational.json-simplify-10 [=>]36.3

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

      rational.json-simplify-61 [=>]36.3

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

      metadata-eval [<=]36.3

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

      rational.json-simplify-35 [<=]36.3

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

      rational.json-simplify-7 [=>]36.3

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

    if -2.35000000000000002e136 < re < -4.39999999999999971e-15

    1. Initial program 48.6

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

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

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

      [Start]39.2

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

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

      \[ 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. Simplified41.1

      \[\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.json-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.json-simplify-9 [=>]64.0

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

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

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

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

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

      rational.json-simplify-43 [=>]64.0

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

      exponential.json-simplify-20 [=>]41.1

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

      rational.json-simplify-8 [<=]41.1

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

      rational.json-simplify-10 [=>]41.1

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

      rational.json-simplify-35 [=>]41.1

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

      metadata-eval [=>]41.1

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

      rational.json-simplify-46 [<=]41.1

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

      rational.json-simplify-8 [<=]41.1

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

      rational.json-simplify-10 [=>]41.1

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

      rational.json-simplify-61 [=>]41.1

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

      metadata-eval [<=]41.1

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

      rational.json-simplify-35 [<=]41.1

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

      rational.json-simplify-7 [=>]41.1

      \[ 0.5 \cdot \left(-im \cdot \sqrt{\frac{-1}{\color{blue}{re}}}\right) \]
    6. Applied egg-rr41.1

      \[\leadsto \color{blue}{\frac{im \cdot \sqrt{\frac{-1}{re}}}{-2}} \]

    if -1.0799999999999999e-97 < re < -8.59999999999999921e-276

    1. Initial program 31.7

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

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

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

      [Start]38.8

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

      exponential.json-simplify-20 [=>]38.6

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

    if -8.59999999999999921e-276 < re < 1e-224 or 2.00000000000000008e-166 < re < 6.20000000000000026e-102

    1. Initial program 23.8

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

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

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

      [Start]35.3

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

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

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

      rational.json-simplify-9 [=>]35.3

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

    if 1e-224 < re < 2.00000000000000008e-166

    1. Initial program 28.3

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

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

    if 6.20000000000000026e-102 < re

    1. Initial program 34.9

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

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

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

      [Start]21.2

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

      exponential.json-simplify-24 [=>]20.3

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

      metadata-eval [=>]20.3

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

      metadata-eval [=>]20.3

      \[ 0.5 \cdot \left(\color{blue}{2} \cdot \sqrt{re}\right) \]
  3. Recombined 6 regimes into one program.
  4. Final simplification31.7

    \[\leadsto \begin{array}{l} \mathbf{if}\;re \leq -2.35 \cdot 10^{+136}:\\ \;\;\;\;0.5 \cdot \left(im \cdot \sqrt{\frac{-1}{re}}\right)\\ \mathbf{elif}\;re \leq -4.4 \cdot 10^{-15}:\\ \;\;\;\;\frac{im \cdot \sqrt{\frac{-1}{re}}}{-2}\\ \mathbf{elif}\;re \leq -1.08 \cdot 10^{-97}:\\ \;\;\;\;0.5 \cdot \left(im \cdot \sqrt{\frac{-1}{re}}\right)\\ \mathbf{elif}\;re \leq -8.6 \cdot 10^{-276}:\\ \;\;\;\;0.5 \cdot \sqrt{im \cdot 2}\\ \mathbf{elif}\;re \leq 10^{-224}:\\ \;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(\left(-im\right) + re\right)}\\ \mathbf{elif}\;re \leq 2 \cdot 10^{-166}:\\ \;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(re + im\right)}\\ \mathbf{elif}\;re \leq 6.2 \cdot 10^{-102}:\\ \;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(\left(-im\right) + re\right)}\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \left(2 \cdot \sqrt{re}\right)\\ \end{array} \]

Alternatives

Alternative 1
Error26.6
Cost14028
\[\begin{array}{l} t_0 := im \cdot \sqrt{\frac{-1}{re}}\\ \mathbf{if}\;re \leq -2.4 \cdot 10^{+137}:\\ \;\;\;\;0.5 \cdot t_0\\ \mathbf{elif}\;re \leq -7.8 \cdot 10^{-19}:\\ \;\;\;\;\frac{t_0}{-2}\\ \mathbf{elif}\;re \leq 180000000000:\\ \;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \left(2 \cdot \sqrt{re}\right)\\ \end{array} \]
Alternative 2
Error31.8
Cost7376
\[\begin{array}{l} t_0 := im \cdot \sqrt{\frac{-1}{re}}\\ t_1 := 0.5 \cdot t_0\\ \mathbf{if}\;re \leq -2.8 \cdot 10^{+139}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;re \leq -3.6 \cdot 10^{-13}:\\ \;\;\;\;\frac{t_0}{-2}\\ \mathbf{elif}\;re \leq -2.8 \cdot 10^{-96}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;re \leq 9.2 \cdot 10^{-48}:\\ \;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(re + im\right)}\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \left(2 \cdot \sqrt{re}\right)\\ \end{array} \]
Alternative 3
Error31.7
Cost7112
\[\begin{array}{l} \mathbf{if}\;re \leq -1.52 \cdot 10^{-78}:\\ \;\;\;\;0.5 \cdot \left(im \cdot \sqrt{\frac{-1}{re}}\right)\\ \mathbf{elif}\;re \leq 3.7 \cdot 10^{-56}:\\ \;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(re + im\right)}\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \left(2 \cdot \sqrt{re}\right)\\ \end{array} \]
Alternative 4
Error31.9
Cost7112
\[\begin{array}{l} \mathbf{if}\;re \leq -2.1 \cdot 10^{-96}:\\ \;\;\;\;\sqrt{\frac{-1}{re}} \cdot \left(im \cdot 0.5\right)\\ \mathbf{elif}\;re \leq 2.1 \cdot 10^{-49}:\\ \;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(re + im\right)}\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \left(2 \cdot \sqrt{re}\right)\\ \end{array} \]
Alternative 5
Error36.3
Cost6980
\[\begin{array}{l} \mathbf{if}\;im \leq 6.8 \cdot 10^{-122}:\\ \;\;\;\;0.5 \cdot \left(2 \cdot \sqrt{re}\right)\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(re + im\right)}\\ \end{array} \]
Alternative 6
Error37.0
Cost6852
\[\begin{array}{l} \mathbf{if}\;im \leq 1.8 \cdot 10^{-73}:\\ \;\;\;\;0.5 \cdot \left(2 \cdot \sqrt{re}\right)\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \sqrt{im \cdot 2}\\ \end{array} \]
Alternative 7
Error47.4
Cost6720
\[0.5 \cdot \sqrt{im \cdot 2} \]

Error

Reproduce?

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