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

Percentage Accurate: 41.2% → 87.5%
Time: 6.8s
Alternatives: 13
Speedup: 2.5×

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)));
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(8) function code(re, im)
use fmin_fmax_functions
    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 13 alternatives:

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

Initial Program: 41.2% 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)));
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(8) function code(re, im)
use fmin_fmax_functions
    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: 87.5% accurate, 0.1× speedup?

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

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

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


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

    1. Initial program 55.2%

      \[0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. lift-*.f64N/A

        \[\leadsto \color{blue}{\frac{1}{2} \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)}} \]
      2. *-commutativeN/A

        \[\leadsto \color{blue}{\sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)} \cdot \frac{1}{2}} \]
      3. lower-*.f6455.2

        \[\leadsto \color{blue}{\sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)} \cdot 0.5} \]
      4. lift-*.f64N/A

        \[\leadsto \sqrt{\color{blue}{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)}} \cdot \frac{1}{2} \]
      5. *-commutativeN/A

        \[\leadsto \sqrt{\color{blue}{\left(\sqrt{re \cdot re + im \cdot im} - re\right) \cdot 2}} \cdot \frac{1}{2} \]
      6. lower-*.f6455.2

        \[\leadsto \sqrt{\color{blue}{\left(\sqrt{re \cdot re + im \cdot im} - re\right) \cdot 2}} \cdot 0.5 \]
      7. lift-sqrt.f64N/A

        \[\leadsto \sqrt{\left(\color{blue}{\sqrt{re \cdot re + im \cdot im}} - re\right) \cdot 2} \cdot \frac{1}{2} \]
      8. lift-+.f64N/A

        \[\leadsto \sqrt{\left(\sqrt{\color{blue}{re \cdot re + im \cdot im}} - re\right) \cdot 2} \cdot \frac{1}{2} \]
      9. +-commutativeN/A

        \[\leadsto \sqrt{\left(\sqrt{\color{blue}{im \cdot im + re \cdot re}} - re\right) \cdot 2} \cdot \frac{1}{2} \]
      10. lift-*.f64N/A

        \[\leadsto \sqrt{\left(\sqrt{\color{blue}{im \cdot im} + re \cdot re} - re\right) \cdot 2} \cdot \frac{1}{2} \]
      11. lift-*.f64N/A

        \[\leadsto \sqrt{\left(\sqrt{im \cdot im + \color{blue}{re \cdot re}} - re\right) \cdot 2} \cdot \frac{1}{2} \]
      12. lower-hypot.f6495.2

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

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

    if 2.1e-35 < re

    1. Initial program 10.5%

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

      \[\leadsto \color{blue}{\frac{1}{2} \cdot \left(\left(im \cdot \left(\sqrt{\frac{1}{2}} \cdot \sqrt{2}\right)\right) \cdot \sqrt{\frac{1}{re}}\right)} \]
    4. Step-by-step derivation
      1. associate-*r*N/A

        \[\leadsto \color{blue}{\left(\frac{1}{2} \cdot \left(im \cdot \left(\sqrt{\frac{1}{2}} \cdot \sqrt{2}\right)\right)\right) \cdot \sqrt{\frac{1}{re}}} \]
      2. lower-*.f64N/A

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

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

        \[\leadsto \color{blue}{\left(\left(\frac{1}{2} \cdot \left(im \cdot \sqrt{\frac{1}{2}}\right)\right) \cdot \sqrt{2}\right)} \cdot \sqrt{\frac{1}{re}} \]
      5. lower-*.f64N/A

        \[\leadsto \color{blue}{\left(\left(\frac{1}{2} \cdot \left(im \cdot \sqrt{\frac{1}{2}}\right)\right) \cdot \sqrt{2}\right)} \cdot \sqrt{\frac{1}{re}} \]
      6. lower-*.f64N/A

        \[\leadsto \left(\color{blue}{\left(\frac{1}{2} \cdot \left(im \cdot \sqrt{\frac{1}{2}}\right)\right)} \cdot \sqrt{2}\right) \cdot \sqrt{\frac{1}{re}} \]
      7. *-commutativeN/A

        \[\leadsto \left(\left(\frac{1}{2} \cdot \color{blue}{\left(\sqrt{\frac{1}{2}} \cdot im\right)}\right) \cdot \sqrt{2}\right) \cdot \sqrt{\frac{1}{re}} \]
      8. lower-*.f64N/A

        \[\leadsto \left(\left(\frac{1}{2} \cdot \color{blue}{\left(\sqrt{\frac{1}{2}} \cdot im\right)}\right) \cdot \sqrt{2}\right) \cdot \sqrt{\frac{1}{re}} \]
      9. lower-sqrt.f64N/A

        \[\leadsto \left(\left(\frac{1}{2} \cdot \left(\color{blue}{\sqrt{\frac{1}{2}}} \cdot im\right)\right) \cdot \sqrt{2}\right) \cdot \sqrt{\frac{1}{re}} \]
      10. lower-sqrt.f64N/A

        \[\leadsto \left(\left(\frac{1}{2} \cdot \left(\sqrt{\frac{1}{2}} \cdot im\right)\right) \cdot \color{blue}{\sqrt{2}}\right) \cdot \sqrt{\frac{1}{re}} \]
      11. lower-sqrt.f64N/A

        \[\leadsto \left(\left(\frac{1}{2} \cdot \left(\sqrt{\frac{1}{2}} \cdot im\right)\right) \cdot \sqrt{2}\right) \cdot \color{blue}{\sqrt{\frac{1}{re}}} \]
      12. lower-/.f6475.6

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

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

        \[\leadsto \left(\sqrt{0.5} \cdot 0.5\right) \cdot \color{blue}{\left(im \cdot \left({re}^{-0.5} \cdot \sqrt{2}\right)\right)} \]
      2. Step-by-step derivation
        1. Applied rewrites76.2%

          \[\leadsto \left(\left({0.5}^{0.25} \cdot {0.5}^{0.25}\right) \cdot 0.5\right) \cdot \left(im \cdot \left({re}^{-0.5} \cdot \sqrt{2}\right)\right) \]
      3. Recombined 2 regimes into one program.
      4. Add Preprocessing

      Alternative 2: 87.5% accurate, 0.1× speedup?

      \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;re \leq 2.1 \cdot 10^{-35}:\\ \;\;\;\;\sqrt{\left(\mathsf{hypot}\left(im, re\right) - re\right) \cdot 2} \cdot 0.5\\ \mathbf{else}:\\ \;\;\;\;\left(\left(\sqrt{{re}^{-1}} \cdot \left(\sqrt{0.5} \cdot im\right)\right) \cdot e^{\log 2 \cdot 0.5}\right) \cdot 0.5\\ \end{array} \end{array} \]
      (FPCore (re im)
       :precision binary64
       (if (<= re 2.1e-35)
         (* (sqrt (* (- (hypot im re) re) 2.0)) 0.5)
         (*
          (* (* (sqrt (pow re -1.0)) (* (sqrt 0.5) im)) (exp (* (log 2.0) 0.5)))
          0.5)))
      double code(double re, double im) {
      	double tmp;
      	if (re <= 2.1e-35) {
      		tmp = sqrt(((hypot(im, re) - re) * 2.0)) * 0.5;
      	} else {
      		tmp = ((sqrt(pow(re, -1.0)) * (sqrt(0.5) * im)) * exp((log(2.0) * 0.5))) * 0.5;
      	}
      	return tmp;
      }
      
      public static double code(double re, double im) {
      	double tmp;
      	if (re <= 2.1e-35) {
      		tmp = Math.sqrt(((Math.hypot(im, re) - re) * 2.0)) * 0.5;
      	} else {
      		tmp = ((Math.sqrt(Math.pow(re, -1.0)) * (Math.sqrt(0.5) * im)) * Math.exp((Math.log(2.0) * 0.5))) * 0.5;
      	}
      	return tmp;
      }
      
      def code(re, im):
      	tmp = 0
      	if re <= 2.1e-35:
      		tmp = math.sqrt(((math.hypot(im, re) - re) * 2.0)) * 0.5
      	else:
      		tmp = ((math.sqrt(math.pow(re, -1.0)) * (math.sqrt(0.5) * im)) * math.exp((math.log(2.0) * 0.5))) * 0.5
      	return tmp
      
      function code(re, im)
      	tmp = 0.0
      	if (re <= 2.1e-35)
      		tmp = Float64(sqrt(Float64(Float64(hypot(im, re) - re) * 2.0)) * 0.5);
      	else
      		tmp = Float64(Float64(Float64(sqrt((re ^ -1.0)) * Float64(sqrt(0.5) * im)) * exp(Float64(log(2.0) * 0.5))) * 0.5);
      	end
      	return tmp
      end
      
      function tmp_2 = code(re, im)
      	tmp = 0.0;
      	if (re <= 2.1e-35)
      		tmp = sqrt(((hypot(im, re) - re) * 2.0)) * 0.5;
      	else
      		tmp = ((sqrt((re ^ -1.0)) * (sqrt(0.5) * im)) * exp((log(2.0) * 0.5))) * 0.5;
      	end
      	tmp_2 = tmp;
      end
      
      code[re_, im_] := If[LessEqual[re, 2.1e-35], N[(N[Sqrt[N[(N[(N[Sqrt[im ^ 2 + re ^ 2], $MachinePrecision] - re), $MachinePrecision] * 2.0), $MachinePrecision]], $MachinePrecision] * 0.5), $MachinePrecision], N[(N[(N[(N[Sqrt[N[Power[re, -1.0], $MachinePrecision]], $MachinePrecision] * N[(N[Sqrt[0.5], $MachinePrecision] * im), $MachinePrecision]), $MachinePrecision] * N[Exp[N[(N[Log[2.0], $MachinePrecision] * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision]]
      
      \begin{array}{l}
      
      \\
      \begin{array}{l}
      \mathbf{if}\;re \leq 2.1 \cdot 10^{-35}:\\
      \;\;\;\;\sqrt{\left(\mathsf{hypot}\left(im, re\right) - re\right) \cdot 2} \cdot 0.5\\
      
      \mathbf{else}:\\
      \;\;\;\;\left(\left(\sqrt{{re}^{-1}} \cdot \left(\sqrt{0.5} \cdot im\right)\right) \cdot e^{\log 2 \cdot 0.5}\right) \cdot 0.5\\
      
      
      \end{array}
      \end{array}
      
      Derivation
      1. Split input into 2 regimes
      2. if re < 2.1e-35

        1. Initial program 55.2%

          \[0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)} \]
        2. Add Preprocessing
        3. Step-by-step derivation
          1. lift-*.f64N/A

            \[\leadsto \color{blue}{\frac{1}{2} \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)}} \]
          2. *-commutativeN/A

            \[\leadsto \color{blue}{\sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)} \cdot \frac{1}{2}} \]
          3. lower-*.f6455.2

            \[\leadsto \color{blue}{\sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)} \cdot 0.5} \]
          4. lift-*.f64N/A

            \[\leadsto \sqrt{\color{blue}{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)}} \cdot \frac{1}{2} \]
          5. *-commutativeN/A

            \[\leadsto \sqrt{\color{blue}{\left(\sqrt{re \cdot re + im \cdot im} - re\right) \cdot 2}} \cdot \frac{1}{2} \]
          6. lower-*.f6455.2

            \[\leadsto \sqrt{\color{blue}{\left(\sqrt{re \cdot re + im \cdot im} - re\right) \cdot 2}} \cdot 0.5 \]
          7. lift-sqrt.f64N/A

            \[\leadsto \sqrt{\left(\color{blue}{\sqrt{re \cdot re + im \cdot im}} - re\right) \cdot 2} \cdot \frac{1}{2} \]
          8. lift-+.f64N/A

            \[\leadsto \sqrt{\left(\sqrt{\color{blue}{re \cdot re + im \cdot im}} - re\right) \cdot 2} \cdot \frac{1}{2} \]
          9. +-commutativeN/A

            \[\leadsto \sqrt{\left(\sqrt{\color{blue}{im \cdot im + re \cdot re}} - re\right) \cdot 2} \cdot \frac{1}{2} \]
          10. lift-*.f64N/A

            \[\leadsto \sqrt{\left(\sqrt{\color{blue}{im \cdot im} + re \cdot re} - re\right) \cdot 2} \cdot \frac{1}{2} \]
          11. lift-*.f64N/A

            \[\leadsto \sqrt{\left(\sqrt{im \cdot im + \color{blue}{re \cdot re}} - re\right) \cdot 2} \cdot \frac{1}{2} \]
          12. lower-hypot.f6495.2

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

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

        if 2.1e-35 < re

        1. Initial program 10.5%

          \[0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)} \]
        2. Add Preprocessing
        3. Step-by-step derivation
          1. lift-*.f64N/A

            \[\leadsto \color{blue}{\frac{1}{2} \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)}} \]
          2. *-commutativeN/A

            \[\leadsto \color{blue}{\sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)} \cdot \frac{1}{2}} \]
          3. lower-*.f6410.5

            \[\leadsto \color{blue}{\sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)} \cdot 0.5} \]
          4. lift-*.f64N/A

            \[\leadsto \sqrt{\color{blue}{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)}} \cdot \frac{1}{2} \]
          5. *-commutativeN/A

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

            \[\leadsto \sqrt{\color{blue}{\left(\sqrt{re \cdot re + im \cdot im} - re\right) \cdot 2}} \cdot 0.5 \]
          7. lift-sqrt.f64N/A

            \[\leadsto \sqrt{\left(\color{blue}{\sqrt{re \cdot re + im \cdot im}} - re\right) \cdot 2} \cdot \frac{1}{2} \]
          8. lift-+.f64N/A

            \[\leadsto \sqrt{\left(\sqrt{\color{blue}{re \cdot re + im \cdot im}} - re\right) \cdot 2} \cdot \frac{1}{2} \]
          9. +-commutativeN/A

            \[\leadsto \sqrt{\left(\sqrt{\color{blue}{im \cdot im + re \cdot re}} - re\right) \cdot 2} \cdot \frac{1}{2} \]
          10. lift-*.f64N/A

            \[\leadsto \sqrt{\left(\sqrt{\color{blue}{im \cdot im} + re \cdot re} - re\right) \cdot 2} \cdot \frac{1}{2} \]
          11. lift-*.f64N/A

            \[\leadsto \sqrt{\left(\sqrt{im \cdot im + \color{blue}{re \cdot re}} - re\right) \cdot 2} \cdot \frac{1}{2} \]
          12. lower-hypot.f6438.4

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

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

          \[\leadsto \color{blue}{\left(\left(im \cdot \left(\sqrt{\frac{1}{2}} \cdot \sqrt{2}\right)\right) \cdot \sqrt{\frac{1}{re}}\right)} \cdot \frac{1}{2} \]
        6. Step-by-step derivation
          1. *-commutativeN/A

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

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

            \[\leadsto \color{blue}{\left(\left(\sqrt{\frac{1}{re}} \cdot \left(im \cdot \sqrt{\frac{1}{2}}\right)\right) \cdot \sqrt{2}\right)} \cdot \frac{1}{2} \]
          4. lower-*.f64N/A

            \[\leadsto \color{blue}{\left(\left(\sqrt{\frac{1}{re}} \cdot \left(im \cdot \sqrt{\frac{1}{2}}\right)\right) \cdot \sqrt{2}\right)} \cdot \frac{1}{2} \]
          5. lower-*.f64N/A

            \[\leadsto \left(\color{blue}{\left(\sqrt{\frac{1}{re}} \cdot \left(im \cdot \sqrt{\frac{1}{2}}\right)\right)} \cdot \sqrt{2}\right) \cdot \frac{1}{2} \]
          6. lower-sqrt.f64N/A

            \[\leadsto \left(\left(\color{blue}{\sqrt{\frac{1}{re}}} \cdot \left(im \cdot \sqrt{\frac{1}{2}}\right)\right) \cdot \sqrt{2}\right) \cdot \frac{1}{2} \]
          7. lower-/.f64N/A

            \[\leadsto \left(\left(\sqrt{\color{blue}{\frac{1}{re}}} \cdot \left(im \cdot \sqrt{\frac{1}{2}}\right)\right) \cdot \sqrt{2}\right) \cdot \frac{1}{2} \]
          8. *-commutativeN/A

            \[\leadsto \left(\left(\sqrt{\frac{1}{re}} \cdot \color{blue}{\left(\sqrt{\frac{1}{2}} \cdot im\right)}\right) \cdot \sqrt{2}\right) \cdot \frac{1}{2} \]
          9. lower-*.f64N/A

            \[\leadsto \left(\left(\sqrt{\frac{1}{re}} \cdot \color{blue}{\left(\sqrt{\frac{1}{2}} \cdot im\right)}\right) \cdot \sqrt{2}\right) \cdot \frac{1}{2} \]
          10. lower-sqrt.f64N/A

            \[\leadsto \left(\left(\sqrt{\frac{1}{re}} \cdot \left(\color{blue}{\sqrt{\frac{1}{2}}} \cdot im\right)\right) \cdot \sqrt{2}\right) \cdot \frac{1}{2} \]
          11. lower-sqrt.f6475.6

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

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

            \[\leadsto \left(\left(\sqrt{\frac{1}{re}} \cdot \left(\sqrt{0.5} \cdot im\right)\right) \cdot e^{\log 2 \cdot 0.5}\right) \cdot 0.5 \]
        9. Recombined 2 regimes into one program.
        10. Final simplification89.6%

          \[\leadsto \begin{array}{l} \mathbf{if}\;re \leq 2.1 \cdot 10^{-35}:\\ \;\;\;\;\sqrt{\left(\mathsf{hypot}\left(im, re\right) - re\right) \cdot 2} \cdot 0.5\\ \mathbf{else}:\\ \;\;\;\;\left(\left(\sqrt{{re}^{-1}} \cdot \left(\sqrt{0.5} \cdot im\right)\right) \cdot e^{\log 2 \cdot 0.5}\right) \cdot 0.5\\ \end{array} \]
        11. Add Preprocessing

        Alternative 3: 78.4% accurate, 0.3× speedup?

        \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;re \leq -7 \cdot 10^{+146}:\\ \;\;\;\;\sqrt{-4 \cdot re} \cdot 0.5\\ \mathbf{elif}\;re \leq -9 \cdot 10^{-125}:\\ \;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(\sqrt{\mathsf{fma}\left(im, im, re \cdot re\right)} - re\right)}\\ \mathbf{elif}\;re \leq 2.1 \cdot 10^{-35}:\\ \;\;\;\;\sqrt{\mathsf{fma}\left(-2, re, im\right) + im} \cdot 0.5\\ \mathbf{else}:\\ \;\;\;\;\left(\sqrt{0.5} \cdot 0.5\right) \cdot \left(im \cdot \left(\sqrt{{re}^{-1}} \cdot \sqrt{2}\right)\right)\\ \end{array} \end{array} \]
        (FPCore (re im)
         :precision binary64
         (if (<= re -7e+146)
           (* (sqrt (* -4.0 re)) 0.5)
           (if (<= re -9e-125)
             (* 0.5 (sqrt (* 2.0 (- (sqrt (fma im im (* re re))) re))))
             (if (<= re 2.1e-35)
               (* (sqrt (+ (fma -2.0 re im) im)) 0.5)
               (* (* (sqrt 0.5) 0.5) (* im (* (sqrt (pow re -1.0)) (sqrt 2.0))))))))
        double code(double re, double im) {
        	double tmp;
        	if (re <= -7e+146) {
        		tmp = sqrt((-4.0 * re)) * 0.5;
        	} else if (re <= -9e-125) {
        		tmp = 0.5 * sqrt((2.0 * (sqrt(fma(im, im, (re * re))) - re)));
        	} else if (re <= 2.1e-35) {
        		tmp = sqrt((fma(-2.0, re, im) + im)) * 0.5;
        	} else {
        		tmp = (sqrt(0.5) * 0.5) * (im * (sqrt(pow(re, -1.0)) * sqrt(2.0)));
        	}
        	return tmp;
        }
        
        function code(re, im)
        	tmp = 0.0
        	if (re <= -7e+146)
        		tmp = Float64(sqrt(Float64(-4.0 * re)) * 0.5);
        	elseif (re <= -9e-125)
        		tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(sqrt(fma(im, im, Float64(re * re))) - re))));
        	elseif (re <= 2.1e-35)
        		tmp = Float64(sqrt(Float64(fma(-2.0, re, im) + im)) * 0.5);
        	else
        		tmp = Float64(Float64(sqrt(0.5) * 0.5) * Float64(im * Float64(sqrt((re ^ -1.0)) * sqrt(2.0))));
        	end
        	return tmp
        end
        
        code[re_, im_] := If[LessEqual[re, -7e+146], N[(N[Sqrt[N[(-4.0 * re), $MachinePrecision]], $MachinePrecision] * 0.5), $MachinePrecision], If[LessEqual[re, -9e-125], N[(0.5 * N[Sqrt[N[(2.0 * N[(N[Sqrt[N[(im * im + N[(re * re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 2.1e-35], N[(N[Sqrt[N[(N[(-2.0 * re + im), $MachinePrecision] + im), $MachinePrecision]], $MachinePrecision] * 0.5), $MachinePrecision], N[(N[(N[Sqrt[0.5], $MachinePrecision] * 0.5), $MachinePrecision] * N[(im * N[(N[Sqrt[N[Power[re, -1.0], $MachinePrecision]], $MachinePrecision] * N[Sqrt[2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
        
        \begin{array}{l}
        
        \\
        \begin{array}{l}
        \mathbf{if}\;re \leq -7 \cdot 10^{+146}:\\
        \;\;\;\;\sqrt{-4 \cdot re} \cdot 0.5\\
        
        \mathbf{elif}\;re \leq -9 \cdot 10^{-125}:\\
        \;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(\sqrt{\mathsf{fma}\left(im, im, re \cdot re\right)} - re\right)}\\
        
        \mathbf{elif}\;re \leq 2.1 \cdot 10^{-35}:\\
        \;\;\;\;\sqrt{\mathsf{fma}\left(-2, re, im\right) + im} \cdot 0.5\\
        
        \mathbf{else}:\\
        \;\;\;\;\left(\sqrt{0.5} \cdot 0.5\right) \cdot \left(im \cdot \left(\sqrt{{re}^{-1}} \cdot \sqrt{2}\right)\right)\\
        
        
        \end{array}
        \end{array}
        
        Derivation
        1. Split input into 4 regimes
        2. if re < -7.0000000000000002e146

          1. Initial program 4.2%

            \[0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)} \]
          2. Add Preprocessing
          3. Step-by-step derivation
            1. lift-*.f64N/A

              \[\leadsto \color{blue}{\frac{1}{2} \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)}} \]
            2. *-commutativeN/A

              \[\leadsto \color{blue}{\sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)} \cdot \frac{1}{2}} \]
            3. lower-*.f644.2

              \[\leadsto \color{blue}{\sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)} \cdot 0.5} \]
            4. lift-*.f64N/A

              \[\leadsto \sqrt{\color{blue}{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)}} \cdot \frac{1}{2} \]
            5. *-commutativeN/A

              \[\leadsto \sqrt{\color{blue}{\left(\sqrt{re \cdot re + im \cdot im} - re\right) \cdot 2}} \cdot \frac{1}{2} \]
            6. lower-*.f644.2

              \[\leadsto \sqrt{\color{blue}{\left(\sqrt{re \cdot re + im \cdot im} - re\right) \cdot 2}} \cdot 0.5 \]
            7. lift-sqrt.f64N/A

              \[\leadsto \sqrt{\left(\color{blue}{\sqrt{re \cdot re + im \cdot im}} - re\right) \cdot 2} \cdot \frac{1}{2} \]
            8. lift-+.f64N/A

              \[\leadsto \sqrt{\left(\sqrt{\color{blue}{re \cdot re + im \cdot im}} - re\right) \cdot 2} \cdot \frac{1}{2} \]
            9. +-commutativeN/A

              \[\leadsto \sqrt{\left(\sqrt{\color{blue}{im \cdot im + re \cdot re}} - re\right) \cdot 2} \cdot \frac{1}{2} \]
            10. lift-*.f64N/A

              \[\leadsto \sqrt{\left(\sqrt{\color{blue}{im \cdot im} + re \cdot re} - re\right) \cdot 2} \cdot \frac{1}{2} \]
            11. lift-*.f64N/A

              \[\leadsto \sqrt{\left(\sqrt{im \cdot im + \color{blue}{re \cdot re}} - re\right) \cdot 2} \cdot \frac{1}{2} \]
            12. lower-hypot.f64100.0

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

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

            \[\leadsto \sqrt{\color{blue}{-4 \cdot re}} \cdot \frac{1}{2} \]
          6. Step-by-step derivation
            1. lower-*.f6484.4

              \[\leadsto \sqrt{\color{blue}{-4 \cdot re}} \cdot 0.5 \]
          7. Applied rewrites84.4%

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

          if -7.0000000000000002e146 < re < -9.00000000000000024e-125

          1. Initial program 79.6%

            \[0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)} \]
          2. Add Preprocessing
          3. Step-by-step derivation
            1. lift-+.f64N/A

              \[\leadsto \frac{1}{2} \cdot \sqrt{2 \cdot \left(\sqrt{\color{blue}{re \cdot re + im \cdot im}} - re\right)} \]
            2. +-commutativeN/A

              \[\leadsto \frac{1}{2} \cdot \sqrt{2 \cdot \left(\sqrt{\color{blue}{im \cdot im + re \cdot re}} - re\right)} \]
            3. lift-*.f64N/A

              \[\leadsto \frac{1}{2} \cdot \sqrt{2 \cdot \left(\sqrt{\color{blue}{im \cdot im} + re \cdot re} - re\right)} \]
            4. lower-fma.f6479.6

              \[\leadsto 0.5 \cdot \sqrt{2 \cdot \left(\sqrt{\color{blue}{\mathsf{fma}\left(im, im, re \cdot re\right)}} - re\right)} \]
          4. Applied rewrites79.6%

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

          if -9.00000000000000024e-125 < re < 2.1e-35

          1. Initial program 50.4%

            \[0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)} \]
          2. Add Preprocessing
          3. Step-by-step derivation
            1. lift-*.f64N/A

              \[\leadsto \color{blue}{\frac{1}{2} \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)}} \]
            2. *-commutativeN/A

              \[\leadsto \color{blue}{\sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)} \cdot \frac{1}{2}} \]
            3. lower-*.f6450.4

              \[\leadsto \color{blue}{\sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)} \cdot 0.5} \]
            4. lift-*.f64N/A

              \[\leadsto \sqrt{\color{blue}{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)}} \cdot \frac{1}{2} \]
            5. *-commutativeN/A

              \[\leadsto \sqrt{\color{blue}{\left(\sqrt{re \cdot re + im \cdot im} - re\right) \cdot 2}} \cdot \frac{1}{2} \]
            6. lower-*.f6450.4

              \[\leadsto \sqrt{\color{blue}{\left(\sqrt{re \cdot re + im \cdot im} - re\right) \cdot 2}} \cdot 0.5 \]
            7. lift-sqrt.f64N/A

              \[\leadsto \sqrt{\left(\color{blue}{\sqrt{re \cdot re + im \cdot im}} - re\right) \cdot 2} \cdot \frac{1}{2} \]
            8. lift-+.f64N/A

              \[\leadsto \sqrt{\left(\sqrt{\color{blue}{re \cdot re + im \cdot im}} - re\right) \cdot 2} \cdot \frac{1}{2} \]
            9. +-commutativeN/A

              \[\leadsto \sqrt{\left(\sqrt{\color{blue}{im \cdot im + re \cdot re}} - re\right) \cdot 2} \cdot \frac{1}{2} \]
            10. lift-*.f64N/A

              \[\leadsto \sqrt{\left(\sqrt{\color{blue}{im \cdot im} + re \cdot re} - re\right) \cdot 2} \cdot \frac{1}{2} \]
            11. lift-*.f64N/A

              \[\leadsto \sqrt{\left(\sqrt{im \cdot im + \color{blue}{re \cdot re}} - re\right) \cdot 2} \cdot \frac{1}{2} \]
            12. lower-hypot.f6490.7

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

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

            \[\leadsto \sqrt{\color{blue}{2 \cdot im + re \cdot \left(\frac{re}{im} - 2\right)}} \cdot \frac{1}{2} \]
          6. Step-by-step derivation
            1. +-commutativeN/A

              \[\leadsto \sqrt{\color{blue}{re \cdot \left(\frac{re}{im} - 2\right) + 2 \cdot im}} \cdot \frac{1}{2} \]
            2. *-commutativeN/A

              \[\leadsto \sqrt{\color{blue}{\left(\frac{re}{im} - 2\right) \cdot re} + 2 \cdot im} \cdot \frac{1}{2} \]
            3. lower-fma.f64N/A

              \[\leadsto \sqrt{\color{blue}{\mathsf{fma}\left(\frac{re}{im} - 2, re, 2 \cdot im\right)}} \cdot \frac{1}{2} \]
            4. lower--.f64N/A

              \[\leadsto \sqrt{\mathsf{fma}\left(\color{blue}{\frac{re}{im} - 2}, re, 2 \cdot im\right)} \cdot \frac{1}{2} \]
            5. lower-/.f64N/A

              \[\leadsto \sqrt{\mathsf{fma}\left(\color{blue}{\frac{re}{im}} - 2, re, 2 \cdot im\right)} \cdot \frac{1}{2} \]
            6. lower-*.f6483.8

              \[\leadsto \sqrt{\mathsf{fma}\left(\frac{re}{im} - 2, re, \color{blue}{2 \cdot im}\right)} \cdot 0.5 \]
          7. Applied rewrites83.8%

            \[\leadsto \sqrt{\color{blue}{\mathsf{fma}\left(\frac{re}{im} - 2, re, 2 \cdot im\right)}} \cdot 0.5 \]
          8. Step-by-step derivation
            1. Applied rewrites83.8%

              \[\leadsto \sqrt{\mathsf{fma}\left(\frac{re}{im} - 2, re, im\right) + \color{blue}{im}} \cdot 0.5 \]
            2. Taylor expanded in re around 0

              \[\leadsto \sqrt{\left(im + -2 \cdot re\right) + im} \cdot \frac{1}{2} \]
            3. Step-by-step derivation
              1. Applied rewrites84.1%

                \[\leadsto \sqrt{\mathsf{fma}\left(-2, re, im\right) + im} \cdot 0.5 \]

              if 2.1e-35 < re

              1. Initial program 10.5%

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

                \[\leadsto \color{blue}{\frac{1}{2} \cdot \left(\left(im \cdot \left(\sqrt{\frac{1}{2}} \cdot \sqrt{2}\right)\right) \cdot \sqrt{\frac{1}{re}}\right)} \]
              4. Step-by-step derivation
                1. associate-*r*N/A

                  \[\leadsto \color{blue}{\left(\frac{1}{2} \cdot \left(im \cdot \left(\sqrt{\frac{1}{2}} \cdot \sqrt{2}\right)\right)\right) \cdot \sqrt{\frac{1}{re}}} \]
                2. lower-*.f64N/A

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

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

                  \[\leadsto \color{blue}{\left(\left(\frac{1}{2} \cdot \left(im \cdot \sqrt{\frac{1}{2}}\right)\right) \cdot \sqrt{2}\right)} \cdot \sqrt{\frac{1}{re}} \]
                5. lower-*.f64N/A

                  \[\leadsto \color{blue}{\left(\left(\frac{1}{2} \cdot \left(im \cdot \sqrt{\frac{1}{2}}\right)\right) \cdot \sqrt{2}\right)} \cdot \sqrt{\frac{1}{re}} \]
                6. lower-*.f64N/A

                  \[\leadsto \left(\color{blue}{\left(\frac{1}{2} \cdot \left(im \cdot \sqrt{\frac{1}{2}}\right)\right)} \cdot \sqrt{2}\right) \cdot \sqrt{\frac{1}{re}} \]
                7. *-commutativeN/A

                  \[\leadsto \left(\left(\frac{1}{2} \cdot \color{blue}{\left(\sqrt{\frac{1}{2}} \cdot im\right)}\right) \cdot \sqrt{2}\right) \cdot \sqrt{\frac{1}{re}} \]
                8. lower-*.f64N/A

                  \[\leadsto \left(\left(\frac{1}{2} \cdot \color{blue}{\left(\sqrt{\frac{1}{2}} \cdot im\right)}\right) \cdot \sqrt{2}\right) \cdot \sqrt{\frac{1}{re}} \]
                9. lower-sqrt.f64N/A

                  \[\leadsto \left(\left(\frac{1}{2} \cdot \left(\color{blue}{\sqrt{\frac{1}{2}}} \cdot im\right)\right) \cdot \sqrt{2}\right) \cdot \sqrt{\frac{1}{re}} \]
                10. lower-sqrt.f64N/A

                  \[\leadsto \left(\left(\frac{1}{2} \cdot \left(\sqrt{\frac{1}{2}} \cdot im\right)\right) \cdot \color{blue}{\sqrt{2}}\right) \cdot \sqrt{\frac{1}{re}} \]
                11. lower-sqrt.f64N/A

                  \[\leadsto \left(\left(\frac{1}{2} \cdot \left(\sqrt{\frac{1}{2}} \cdot im\right)\right) \cdot \sqrt{2}\right) \cdot \color{blue}{\sqrt{\frac{1}{re}}} \]
                12. lower-/.f6475.6

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

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

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

                  \[\leadsto \left(\sqrt{\frac{1}{2}} \cdot \frac{1}{2}\right) \cdot \left(im \cdot \left(\sqrt{\frac{1}{re}} \cdot \color{blue}{\sqrt{2}}\right)\right) \]
                3. Step-by-step derivation
                  1. Applied rewrites75.7%

                    \[\leadsto \left(\sqrt{0.5} \cdot 0.5\right) \cdot \left(im \cdot \left(\sqrt{\frac{1}{re}} \cdot \color{blue}{\sqrt{2}}\right)\right) \]
                4. Recombined 4 regimes into one program.
                5. Final simplification80.5%

                  \[\leadsto \begin{array}{l} \mathbf{if}\;re \leq -7 \cdot 10^{+146}:\\ \;\;\;\;\sqrt{-4 \cdot re} \cdot 0.5\\ \mathbf{elif}\;re \leq -9 \cdot 10^{-125}:\\ \;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(\sqrt{\mathsf{fma}\left(im, im, re \cdot re\right)} - re\right)}\\ \mathbf{elif}\;re \leq 2.1 \cdot 10^{-35}:\\ \;\;\;\;\sqrt{\mathsf{fma}\left(-2, re, im\right) + im} \cdot 0.5\\ \mathbf{else}:\\ \;\;\;\;\left(\sqrt{0.5} \cdot 0.5\right) \cdot \left(im \cdot \left(\sqrt{{re}^{-1}} \cdot \sqrt{2}\right)\right)\\ \end{array} \]
                6. Add Preprocessing

                Alternative 4: 87.5% accurate, 0.3× speedup?

                \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;re \leq 2.45 \cdot 10^{-32}:\\ \;\;\;\;\sqrt{\left(\mathsf{hypot}\left(im, re\right) - re\right) \cdot 2} \cdot 0.5\\ \mathbf{else}:\\ \;\;\;\;\left(\sqrt{0.5} \cdot 0.5\right) \cdot \left(im \cdot \left(\sqrt{{re}^{-1}} \cdot \sqrt{2}\right)\right)\\ \end{array} \end{array} \]
                (FPCore (re im)
                 :precision binary64
                 (if (<= re 2.45e-32)
                   (* (sqrt (* (- (hypot im re) re) 2.0)) 0.5)
                   (* (* (sqrt 0.5) 0.5) (* im (* (sqrt (pow re -1.0)) (sqrt 2.0))))))
                double code(double re, double im) {
                	double tmp;
                	if (re <= 2.45e-32) {
                		tmp = sqrt(((hypot(im, re) - re) * 2.0)) * 0.5;
                	} else {
                		tmp = (sqrt(0.5) * 0.5) * (im * (sqrt(pow(re, -1.0)) * sqrt(2.0)));
                	}
                	return tmp;
                }
                
                public static double code(double re, double im) {
                	double tmp;
                	if (re <= 2.45e-32) {
                		tmp = Math.sqrt(((Math.hypot(im, re) - re) * 2.0)) * 0.5;
                	} else {
                		tmp = (Math.sqrt(0.5) * 0.5) * (im * (Math.sqrt(Math.pow(re, -1.0)) * Math.sqrt(2.0)));
                	}
                	return tmp;
                }
                
                def code(re, im):
                	tmp = 0
                	if re <= 2.45e-32:
                		tmp = math.sqrt(((math.hypot(im, re) - re) * 2.0)) * 0.5
                	else:
                		tmp = (math.sqrt(0.5) * 0.5) * (im * (math.sqrt(math.pow(re, -1.0)) * math.sqrt(2.0)))
                	return tmp
                
                function code(re, im)
                	tmp = 0.0
                	if (re <= 2.45e-32)
                		tmp = Float64(sqrt(Float64(Float64(hypot(im, re) - re) * 2.0)) * 0.5);
                	else
                		tmp = Float64(Float64(sqrt(0.5) * 0.5) * Float64(im * Float64(sqrt((re ^ -1.0)) * sqrt(2.0))));
                	end
                	return tmp
                end
                
                function tmp_2 = code(re, im)
                	tmp = 0.0;
                	if (re <= 2.45e-32)
                		tmp = sqrt(((hypot(im, re) - re) * 2.0)) * 0.5;
                	else
                		tmp = (sqrt(0.5) * 0.5) * (im * (sqrt((re ^ -1.0)) * sqrt(2.0)));
                	end
                	tmp_2 = tmp;
                end
                
                code[re_, im_] := If[LessEqual[re, 2.45e-32], N[(N[Sqrt[N[(N[(N[Sqrt[im ^ 2 + re ^ 2], $MachinePrecision] - re), $MachinePrecision] * 2.0), $MachinePrecision]], $MachinePrecision] * 0.5), $MachinePrecision], N[(N[(N[Sqrt[0.5], $MachinePrecision] * 0.5), $MachinePrecision] * N[(im * N[(N[Sqrt[N[Power[re, -1.0], $MachinePrecision]], $MachinePrecision] * N[Sqrt[2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
                
                \begin{array}{l}
                
                \\
                \begin{array}{l}
                \mathbf{if}\;re \leq 2.45 \cdot 10^{-32}:\\
                \;\;\;\;\sqrt{\left(\mathsf{hypot}\left(im, re\right) - re\right) \cdot 2} \cdot 0.5\\
                
                \mathbf{else}:\\
                \;\;\;\;\left(\sqrt{0.5} \cdot 0.5\right) \cdot \left(im \cdot \left(\sqrt{{re}^{-1}} \cdot \sqrt{2}\right)\right)\\
                
                
                \end{array}
                \end{array}
                
                Derivation
                1. Split input into 2 regimes
                2. if re < 2.4499999999999999e-32

                  1. Initial program 55.2%

                    \[0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)} \]
                  2. Add Preprocessing
                  3. Step-by-step derivation
                    1. lift-*.f64N/A

                      \[\leadsto \color{blue}{\frac{1}{2} \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)}} \]
                    2. *-commutativeN/A

                      \[\leadsto \color{blue}{\sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)} \cdot \frac{1}{2}} \]
                    3. lower-*.f6455.2

                      \[\leadsto \color{blue}{\sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)} \cdot 0.5} \]
                    4. lift-*.f64N/A

                      \[\leadsto \sqrt{\color{blue}{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)}} \cdot \frac{1}{2} \]
                    5. *-commutativeN/A

                      \[\leadsto \sqrt{\color{blue}{\left(\sqrt{re \cdot re + im \cdot im} - re\right) \cdot 2}} \cdot \frac{1}{2} \]
                    6. lower-*.f6455.2

                      \[\leadsto \sqrt{\color{blue}{\left(\sqrt{re \cdot re + im \cdot im} - re\right) \cdot 2}} \cdot 0.5 \]
                    7. lift-sqrt.f64N/A

                      \[\leadsto \sqrt{\left(\color{blue}{\sqrt{re \cdot re + im \cdot im}} - re\right) \cdot 2} \cdot \frac{1}{2} \]
                    8. lift-+.f64N/A

                      \[\leadsto \sqrt{\left(\sqrt{\color{blue}{re \cdot re + im \cdot im}} - re\right) \cdot 2} \cdot \frac{1}{2} \]
                    9. +-commutativeN/A

                      \[\leadsto \sqrt{\left(\sqrt{\color{blue}{im \cdot im + re \cdot re}} - re\right) \cdot 2} \cdot \frac{1}{2} \]
                    10. lift-*.f64N/A

                      \[\leadsto \sqrt{\left(\sqrt{\color{blue}{im \cdot im} + re \cdot re} - re\right) \cdot 2} \cdot \frac{1}{2} \]
                    11. lift-*.f64N/A

                      \[\leadsto \sqrt{\left(\sqrt{im \cdot im + \color{blue}{re \cdot re}} - re\right) \cdot 2} \cdot \frac{1}{2} \]
                    12. lower-hypot.f6495.2

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

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

                  if 2.4499999999999999e-32 < re

                  1. Initial program 10.5%

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

                    \[\leadsto \color{blue}{\frac{1}{2} \cdot \left(\left(im \cdot \left(\sqrt{\frac{1}{2}} \cdot \sqrt{2}\right)\right) \cdot \sqrt{\frac{1}{re}}\right)} \]
                  4. Step-by-step derivation
                    1. associate-*r*N/A

                      \[\leadsto \color{blue}{\left(\frac{1}{2} \cdot \left(im \cdot \left(\sqrt{\frac{1}{2}} \cdot \sqrt{2}\right)\right)\right) \cdot \sqrt{\frac{1}{re}}} \]
                    2. lower-*.f64N/A

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

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

                      \[\leadsto \color{blue}{\left(\left(\frac{1}{2} \cdot \left(im \cdot \sqrt{\frac{1}{2}}\right)\right) \cdot \sqrt{2}\right)} \cdot \sqrt{\frac{1}{re}} \]
                    5. lower-*.f64N/A

                      \[\leadsto \color{blue}{\left(\left(\frac{1}{2} \cdot \left(im \cdot \sqrt{\frac{1}{2}}\right)\right) \cdot \sqrt{2}\right)} \cdot \sqrt{\frac{1}{re}} \]
                    6. lower-*.f64N/A

                      \[\leadsto \left(\color{blue}{\left(\frac{1}{2} \cdot \left(im \cdot \sqrt{\frac{1}{2}}\right)\right)} \cdot \sqrt{2}\right) \cdot \sqrt{\frac{1}{re}} \]
                    7. *-commutativeN/A

                      \[\leadsto \left(\left(\frac{1}{2} \cdot \color{blue}{\left(\sqrt{\frac{1}{2}} \cdot im\right)}\right) \cdot \sqrt{2}\right) \cdot \sqrt{\frac{1}{re}} \]
                    8. lower-*.f64N/A

                      \[\leadsto \left(\left(\frac{1}{2} \cdot \color{blue}{\left(\sqrt{\frac{1}{2}} \cdot im\right)}\right) \cdot \sqrt{2}\right) \cdot \sqrt{\frac{1}{re}} \]
                    9. lower-sqrt.f64N/A

                      \[\leadsto \left(\left(\frac{1}{2} \cdot \left(\color{blue}{\sqrt{\frac{1}{2}}} \cdot im\right)\right) \cdot \sqrt{2}\right) \cdot \sqrt{\frac{1}{re}} \]
                    10. lower-sqrt.f64N/A

                      \[\leadsto \left(\left(\frac{1}{2} \cdot \left(\sqrt{\frac{1}{2}} \cdot im\right)\right) \cdot \color{blue}{\sqrt{2}}\right) \cdot \sqrt{\frac{1}{re}} \]
                    11. lower-sqrt.f64N/A

                      \[\leadsto \left(\left(\frac{1}{2} \cdot \left(\sqrt{\frac{1}{2}} \cdot im\right)\right) \cdot \sqrt{2}\right) \cdot \color{blue}{\sqrt{\frac{1}{re}}} \]
                    12. lower-/.f6475.6

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

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

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

                      \[\leadsto \left(\sqrt{\frac{1}{2}} \cdot \frac{1}{2}\right) \cdot \left(im \cdot \left(\sqrt{\frac{1}{re}} \cdot \color{blue}{\sqrt{2}}\right)\right) \]
                    3. Step-by-step derivation
                      1. Applied rewrites75.7%

                        \[\leadsto \left(\sqrt{0.5} \cdot 0.5\right) \cdot \left(im \cdot \left(\sqrt{\frac{1}{re}} \cdot \color{blue}{\sqrt{2}}\right)\right) \]
                    4. Recombined 2 regimes into one program.
                    5. Final simplification89.5%

                      \[\leadsto \begin{array}{l} \mathbf{if}\;re \leq 2.45 \cdot 10^{-32}:\\ \;\;\;\;\sqrt{\left(\mathsf{hypot}\left(im, re\right) - re\right) \cdot 2} \cdot 0.5\\ \mathbf{else}:\\ \;\;\;\;\left(\sqrt{0.5} \cdot 0.5\right) \cdot \left(im \cdot \left(\sqrt{{re}^{-1}} \cdot \sqrt{2}\right)\right)\\ \end{array} \]
                    6. Add Preprocessing

                    Alternative 5: 69.3% accurate, 0.3× speedup?

                    \[\begin{array}{l} \\ \begin{array}{l} t_0 := 0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)}\\ \mathbf{if}\;t\_0 \leq 5 \cdot 10^{-83}:\\ \;\;\;\;\sqrt{\frac{im \cdot im}{re}} \cdot 0.5\\ \mathbf{elif}\;t\_0 \leq 2 \cdot 10^{+73}:\\ \;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(\sqrt{\mathsf{fma}\left(im, im, re \cdot re\right)} - re\right)}\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(im - re\right)}\\ \end{array} \end{array} \]
                    (FPCore (re im)
                     :precision binary64
                     (let* ((t_0 (* 0.5 (sqrt (* 2.0 (- (sqrt (+ (* re re) (* im im))) re))))))
                       (if (<= t_0 5e-83)
                         (* (sqrt (/ (* im im) re)) 0.5)
                         (if (<= t_0 2e+73)
                           (* 0.5 (sqrt (* 2.0 (- (sqrt (fma im im (* re re))) re))))
                           (* 0.5 (sqrt (* 2.0 (- im re))))))))
                    double code(double re, double im) {
                    	double t_0 = 0.5 * sqrt((2.0 * (sqrt(((re * re) + (im * im))) - re)));
                    	double tmp;
                    	if (t_0 <= 5e-83) {
                    		tmp = sqrt(((im * im) / re)) * 0.5;
                    	} else if (t_0 <= 2e+73) {
                    		tmp = 0.5 * sqrt((2.0 * (sqrt(fma(im, im, (re * re))) - re)));
                    	} else {
                    		tmp = 0.5 * sqrt((2.0 * (im - re)));
                    	}
                    	return tmp;
                    }
                    
                    function code(re, im)
                    	t_0 = Float64(0.5 * sqrt(Float64(2.0 * Float64(sqrt(Float64(Float64(re * re) + Float64(im * im))) - re))))
                    	tmp = 0.0
                    	if (t_0 <= 5e-83)
                    		tmp = Float64(sqrt(Float64(Float64(im * im) / re)) * 0.5);
                    	elseif (t_0 <= 2e+73)
                    		tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(sqrt(fma(im, im, Float64(re * re))) - re))));
                    	else
                    		tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(im - re))));
                    	end
                    	return tmp
                    end
                    
                    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]}, If[LessEqual[t$95$0, 5e-83], N[(N[Sqrt[N[(N[(im * im), $MachinePrecision] / re), $MachinePrecision]], $MachinePrecision] * 0.5), $MachinePrecision], If[LessEqual[t$95$0, 2e+73], N[(0.5 * N[Sqrt[N[(2.0 * N[(N[Sqrt[N[(im * im + N[(re * re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(0.5 * N[Sqrt[N[(2.0 * N[(im - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]]
                    
                    \begin{array}{l}
                    
                    \\
                    \begin{array}{l}
                    t_0 := 0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)}\\
                    \mathbf{if}\;t\_0 \leq 5 \cdot 10^{-83}:\\
                    \;\;\;\;\sqrt{\frac{im \cdot im}{re}} \cdot 0.5\\
                    
                    \mathbf{elif}\;t\_0 \leq 2 \cdot 10^{+73}:\\
                    \;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(\sqrt{\mathsf{fma}\left(im, im, re \cdot re\right)} - re\right)}\\
                    
                    \mathbf{else}:\\
                    \;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(im - re\right)}\\
                    
                    
                    \end{array}
                    \end{array}
                    
                    Derivation
                    1. Split input into 3 regimes
                    2. if (*.f64 #s(literal 1/2 binary64) (sqrt.f64 (*.f64 #s(literal 2 binary64) (-.f64 (sqrt.f64 (+.f64 (*.f64 re re) (*.f64 im im))) re)))) < 5e-83

                      1. Initial program 12.7%

                        \[0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)} \]
                      2. Add Preprocessing
                      3. Step-by-step derivation
                        1. lift-*.f64N/A

                          \[\leadsto \color{blue}{\frac{1}{2} \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)}} \]
                        2. *-commutativeN/A

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

                          \[\leadsto \color{blue}{\sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)} \cdot 0.5} \]
                        4. lift-*.f64N/A

                          \[\leadsto \sqrt{\color{blue}{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)}} \cdot \frac{1}{2} \]
                        5. *-commutativeN/A

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

                          \[\leadsto \sqrt{\color{blue}{\left(\sqrt{re \cdot re + im \cdot im} - re\right) \cdot 2}} \cdot 0.5 \]
                        7. lift-sqrt.f64N/A

                          \[\leadsto \sqrt{\left(\color{blue}{\sqrt{re \cdot re + im \cdot im}} - re\right) \cdot 2} \cdot \frac{1}{2} \]
                        8. lift-+.f64N/A

                          \[\leadsto \sqrt{\left(\sqrt{\color{blue}{re \cdot re + im \cdot im}} - re\right) \cdot 2} \cdot \frac{1}{2} \]
                        9. +-commutativeN/A

                          \[\leadsto \sqrt{\left(\sqrt{\color{blue}{im \cdot im + re \cdot re}} - re\right) \cdot 2} \cdot \frac{1}{2} \]
                        10. lift-*.f64N/A

                          \[\leadsto \sqrt{\left(\sqrt{\color{blue}{im \cdot im} + re \cdot re} - re\right) \cdot 2} \cdot \frac{1}{2} \]
                        11. lift-*.f64N/A

                          \[\leadsto \sqrt{\left(\sqrt{im \cdot im + \color{blue}{re \cdot re}} - re\right) \cdot 2} \cdot \frac{1}{2} \]
                        12. lower-hypot.f6426.3

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

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

                        \[\leadsto \sqrt{\color{blue}{\frac{{im}^{2}}{re}}} \cdot \frac{1}{2} \]
                      6. Step-by-step derivation
                        1. lower-/.f64N/A

                          \[\leadsto \sqrt{\color{blue}{\frac{{im}^{2}}{re}}} \cdot \frac{1}{2} \]
                        2. unpow2N/A

                          \[\leadsto \sqrt{\frac{\color{blue}{im \cdot im}}{re}} \cdot \frac{1}{2} \]
                        3. lower-*.f6449.0

                          \[\leadsto \sqrt{\frac{\color{blue}{im \cdot im}}{re}} \cdot 0.5 \]
                      7. Applied rewrites49.0%

                        \[\leadsto \sqrt{\color{blue}{\frac{im \cdot im}{re}}} \cdot 0.5 \]

                      if 5e-83 < (*.f64 #s(literal 1/2 binary64) (sqrt.f64 (*.f64 #s(literal 2 binary64) (-.f64 (sqrt.f64 (+.f64 (*.f64 re re) (*.f64 im im))) re)))) < 1.99999999999999997e73

                      1. Initial program 98.8%

                        \[0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)} \]
                      2. Add Preprocessing
                      3. Step-by-step derivation
                        1. lift-+.f64N/A

                          \[\leadsto \frac{1}{2} \cdot \sqrt{2 \cdot \left(\sqrt{\color{blue}{re \cdot re + im \cdot im}} - re\right)} \]
                        2. +-commutativeN/A

                          \[\leadsto \frac{1}{2} \cdot \sqrt{2 \cdot \left(\sqrt{\color{blue}{im \cdot im + re \cdot re}} - re\right)} \]
                        3. lift-*.f64N/A

                          \[\leadsto \frac{1}{2} \cdot \sqrt{2 \cdot \left(\sqrt{\color{blue}{im \cdot im} + re \cdot re} - re\right)} \]
                        4. lower-fma.f6498.8

                          \[\leadsto 0.5 \cdot \sqrt{2 \cdot \left(\sqrt{\color{blue}{\mathsf{fma}\left(im, im, re \cdot re\right)}} - re\right)} \]
                      4. Applied rewrites98.8%

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

                      if 1.99999999999999997e73 < (*.f64 #s(literal 1/2 binary64) (sqrt.f64 (*.f64 #s(literal 2 binary64) (-.f64 (sqrt.f64 (+.f64 (*.f64 re re) (*.f64 im im))) re))))

                      1. Initial program 6.7%

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

                        \[\leadsto \frac{1}{2} \cdot \sqrt{2 \cdot \color{blue}{\left(im + -1 \cdot re\right)}} \]
                      4. Step-by-step derivation
                        1. fp-cancel-sign-sub-invN/A

                          \[\leadsto \frac{1}{2} \cdot \sqrt{2 \cdot \color{blue}{\left(im - \left(\mathsf{neg}\left(-1\right)\right) \cdot re\right)}} \]
                        2. metadata-evalN/A

                          \[\leadsto \frac{1}{2} \cdot \sqrt{2 \cdot \left(im - \color{blue}{1} \cdot re\right)} \]
                        3. *-lft-identityN/A

                          \[\leadsto \frac{1}{2} \cdot \sqrt{2 \cdot \left(im - \color{blue}{re}\right)} \]
                        4. lower--.f6459.5

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

                        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \color{blue}{\left(im - re\right)}} \]
                    3. Recombined 3 regimes into one program.
                    4. Add Preprocessing

                    Alternative 6: 87.5% accurate, 0.3× speedup?

                    \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;re \leq 2.45 \cdot 10^{-32}:\\ \;\;\;\;\sqrt{\left(\mathsf{hypot}\left(im, re\right) - re\right) \cdot 2} \cdot 0.5\\ \mathbf{else}:\\ \;\;\;\;\left(\sqrt{0.5} \cdot 0.5\right) \cdot \left(im \cdot \left({re}^{-0.5} \cdot \sqrt{2}\right)\right)\\ \end{array} \end{array} \]
                    (FPCore (re im)
                     :precision binary64
                     (if (<= re 2.45e-32)
                       (* (sqrt (* (- (hypot im re) re) 2.0)) 0.5)
                       (* (* (sqrt 0.5) 0.5) (* im (* (pow re -0.5) (sqrt 2.0))))))
                    double code(double re, double im) {
                    	double tmp;
                    	if (re <= 2.45e-32) {
                    		tmp = sqrt(((hypot(im, re) - re) * 2.0)) * 0.5;
                    	} else {
                    		tmp = (sqrt(0.5) * 0.5) * (im * (pow(re, -0.5) * sqrt(2.0)));
                    	}
                    	return tmp;
                    }
                    
                    public static double code(double re, double im) {
                    	double tmp;
                    	if (re <= 2.45e-32) {
                    		tmp = Math.sqrt(((Math.hypot(im, re) - re) * 2.0)) * 0.5;
                    	} else {
                    		tmp = (Math.sqrt(0.5) * 0.5) * (im * (Math.pow(re, -0.5) * Math.sqrt(2.0)));
                    	}
                    	return tmp;
                    }
                    
                    def code(re, im):
                    	tmp = 0
                    	if re <= 2.45e-32:
                    		tmp = math.sqrt(((math.hypot(im, re) - re) * 2.0)) * 0.5
                    	else:
                    		tmp = (math.sqrt(0.5) * 0.5) * (im * (math.pow(re, -0.5) * math.sqrt(2.0)))
                    	return tmp
                    
                    function code(re, im)
                    	tmp = 0.0
                    	if (re <= 2.45e-32)
                    		tmp = Float64(sqrt(Float64(Float64(hypot(im, re) - re) * 2.0)) * 0.5);
                    	else
                    		tmp = Float64(Float64(sqrt(0.5) * 0.5) * Float64(im * Float64((re ^ -0.5) * sqrt(2.0))));
                    	end
                    	return tmp
                    end
                    
                    function tmp_2 = code(re, im)
                    	tmp = 0.0;
                    	if (re <= 2.45e-32)
                    		tmp = sqrt(((hypot(im, re) - re) * 2.0)) * 0.5;
                    	else
                    		tmp = (sqrt(0.5) * 0.5) * (im * ((re ^ -0.5) * sqrt(2.0)));
                    	end
                    	tmp_2 = tmp;
                    end
                    
                    code[re_, im_] := If[LessEqual[re, 2.45e-32], N[(N[Sqrt[N[(N[(N[Sqrt[im ^ 2 + re ^ 2], $MachinePrecision] - re), $MachinePrecision] * 2.0), $MachinePrecision]], $MachinePrecision] * 0.5), $MachinePrecision], N[(N[(N[Sqrt[0.5], $MachinePrecision] * 0.5), $MachinePrecision] * N[(im * N[(N[Power[re, -0.5], $MachinePrecision] * N[Sqrt[2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
                    
                    \begin{array}{l}
                    
                    \\
                    \begin{array}{l}
                    \mathbf{if}\;re \leq 2.45 \cdot 10^{-32}:\\
                    \;\;\;\;\sqrt{\left(\mathsf{hypot}\left(im, re\right) - re\right) \cdot 2} \cdot 0.5\\
                    
                    \mathbf{else}:\\
                    \;\;\;\;\left(\sqrt{0.5} \cdot 0.5\right) \cdot \left(im \cdot \left({re}^{-0.5} \cdot \sqrt{2}\right)\right)\\
                    
                    
                    \end{array}
                    \end{array}
                    
                    Derivation
                    1. Split input into 2 regimes
                    2. if re < 2.4499999999999999e-32

                      1. Initial program 55.2%

                        \[0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)} \]
                      2. Add Preprocessing
                      3. Step-by-step derivation
                        1. lift-*.f64N/A

                          \[\leadsto \color{blue}{\frac{1}{2} \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)}} \]
                        2. *-commutativeN/A

                          \[\leadsto \color{blue}{\sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)} \cdot \frac{1}{2}} \]
                        3. lower-*.f6455.2

                          \[\leadsto \color{blue}{\sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)} \cdot 0.5} \]
                        4. lift-*.f64N/A

                          \[\leadsto \sqrt{\color{blue}{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)}} \cdot \frac{1}{2} \]
                        5. *-commutativeN/A

                          \[\leadsto \sqrt{\color{blue}{\left(\sqrt{re \cdot re + im \cdot im} - re\right) \cdot 2}} \cdot \frac{1}{2} \]
                        6. lower-*.f6455.2

                          \[\leadsto \sqrt{\color{blue}{\left(\sqrt{re \cdot re + im \cdot im} - re\right) \cdot 2}} \cdot 0.5 \]
                        7. lift-sqrt.f64N/A

                          \[\leadsto \sqrt{\left(\color{blue}{\sqrt{re \cdot re + im \cdot im}} - re\right) \cdot 2} \cdot \frac{1}{2} \]
                        8. lift-+.f64N/A

                          \[\leadsto \sqrt{\left(\sqrt{\color{blue}{re \cdot re + im \cdot im}} - re\right) \cdot 2} \cdot \frac{1}{2} \]
                        9. +-commutativeN/A

                          \[\leadsto \sqrt{\left(\sqrt{\color{blue}{im \cdot im + re \cdot re}} - re\right) \cdot 2} \cdot \frac{1}{2} \]
                        10. lift-*.f64N/A

                          \[\leadsto \sqrt{\left(\sqrt{\color{blue}{im \cdot im} + re \cdot re} - re\right) \cdot 2} \cdot \frac{1}{2} \]
                        11. lift-*.f64N/A

                          \[\leadsto \sqrt{\left(\sqrt{im \cdot im + \color{blue}{re \cdot re}} - re\right) \cdot 2} \cdot \frac{1}{2} \]
                        12. lower-hypot.f6495.2

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

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

                      if 2.4499999999999999e-32 < re

                      1. Initial program 10.5%

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

                        \[\leadsto \color{blue}{\frac{1}{2} \cdot \left(\left(im \cdot \left(\sqrt{\frac{1}{2}} \cdot \sqrt{2}\right)\right) \cdot \sqrt{\frac{1}{re}}\right)} \]
                      4. Step-by-step derivation
                        1. associate-*r*N/A

                          \[\leadsto \color{blue}{\left(\frac{1}{2} \cdot \left(im \cdot \left(\sqrt{\frac{1}{2}} \cdot \sqrt{2}\right)\right)\right) \cdot \sqrt{\frac{1}{re}}} \]
                        2. lower-*.f64N/A

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

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

                          \[\leadsto \color{blue}{\left(\left(\frac{1}{2} \cdot \left(im \cdot \sqrt{\frac{1}{2}}\right)\right) \cdot \sqrt{2}\right)} \cdot \sqrt{\frac{1}{re}} \]
                        5. lower-*.f64N/A

                          \[\leadsto \color{blue}{\left(\left(\frac{1}{2} \cdot \left(im \cdot \sqrt{\frac{1}{2}}\right)\right) \cdot \sqrt{2}\right)} \cdot \sqrt{\frac{1}{re}} \]
                        6. lower-*.f64N/A

                          \[\leadsto \left(\color{blue}{\left(\frac{1}{2} \cdot \left(im \cdot \sqrt{\frac{1}{2}}\right)\right)} \cdot \sqrt{2}\right) \cdot \sqrt{\frac{1}{re}} \]
                        7. *-commutativeN/A

                          \[\leadsto \left(\left(\frac{1}{2} \cdot \color{blue}{\left(\sqrt{\frac{1}{2}} \cdot im\right)}\right) \cdot \sqrt{2}\right) \cdot \sqrt{\frac{1}{re}} \]
                        8. lower-*.f64N/A

                          \[\leadsto \left(\left(\frac{1}{2} \cdot \color{blue}{\left(\sqrt{\frac{1}{2}} \cdot im\right)}\right) \cdot \sqrt{2}\right) \cdot \sqrt{\frac{1}{re}} \]
                        9. lower-sqrt.f64N/A

                          \[\leadsto \left(\left(\frac{1}{2} \cdot \left(\color{blue}{\sqrt{\frac{1}{2}}} \cdot im\right)\right) \cdot \sqrt{2}\right) \cdot \sqrt{\frac{1}{re}} \]
                        10. lower-sqrt.f64N/A

                          \[\leadsto \left(\left(\frac{1}{2} \cdot \left(\sqrt{\frac{1}{2}} \cdot im\right)\right) \cdot \color{blue}{\sqrt{2}}\right) \cdot \sqrt{\frac{1}{re}} \]
                        11. lower-sqrt.f64N/A

                          \[\leadsto \left(\left(\frac{1}{2} \cdot \left(\sqrt{\frac{1}{2}} \cdot im\right)\right) \cdot \sqrt{2}\right) \cdot \color{blue}{\sqrt{\frac{1}{re}}} \]
                        12. lower-/.f6475.6

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

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

                          \[\leadsto \left(\sqrt{0.5} \cdot 0.5\right) \cdot \color{blue}{\left(im \cdot \left({re}^{-0.5} \cdot \sqrt{2}\right)\right)} \]
                      7. Recombined 2 regimes into one program.
                      8. Add Preprocessing

                      Alternative 7: 78.3% accurate, 0.6× speedup?

                      \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;re \leq -7 \cdot 10^{+146}:\\ \;\;\;\;\sqrt{-4 \cdot re} \cdot 0.5\\ \mathbf{elif}\;re \leq -9 \cdot 10^{-125}:\\ \;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(\sqrt{\mathsf{fma}\left(im, im, re \cdot re\right)} - re\right)}\\ \mathbf{elif}\;re \leq 2.1 \cdot 10^{-35}:\\ \;\;\;\;\sqrt{\mathsf{fma}\left(-2, re, im\right) + im} \cdot 0.5\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(\sqrt{2} \cdot im\right) \cdot \sqrt{0.5}}{\sqrt{re}} \cdot 0.5\\ \end{array} \end{array} \]
                      (FPCore (re im)
                       :precision binary64
                       (if (<= re -7e+146)
                         (* (sqrt (* -4.0 re)) 0.5)
                         (if (<= re -9e-125)
                           (* 0.5 (sqrt (* 2.0 (- (sqrt (fma im im (* re re))) re))))
                           (if (<= re 2.1e-35)
                             (* (sqrt (+ (fma -2.0 re im) im)) 0.5)
                             (* (/ (* (* (sqrt 2.0) im) (sqrt 0.5)) (sqrt re)) 0.5)))))
                      double code(double re, double im) {
                      	double tmp;
                      	if (re <= -7e+146) {
                      		tmp = sqrt((-4.0 * re)) * 0.5;
                      	} else if (re <= -9e-125) {
                      		tmp = 0.5 * sqrt((2.0 * (sqrt(fma(im, im, (re * re))) - re)));
                      	} else if (re <= 2.1e-35) {
                      		tmp = sqrt((fma(-2.0, re, im) + im)) * 0.5;
                      	} else {
                      		tmp = (((sqrt(2.0) * im) * sqrt(0.5)) / sqrt(re)) * 0.5;
                      	}
                      	return tmp;
                      }
                      
                      function code(re, im)
                      	tmp = 0.0
                      	if (re <= -7e+146)
                      		tmp = Float64(sqrt(Float64(-4.0 * re)) * 0.5);
                      	elseif (re <= -9e-125)
                      		tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(sqrt(fma(im, im, Float64(re * re))) - re))));
                      	elseif (re <= 2.1e-35)
                      		tmp = Float64(sqrt(Float64(fma(-2.0, re, im) + im)) * 0.5);
                      	else
                      		tmp = Float64(Float64(Float64(Float64(sqrt(2.0) * im) * sqrt(0.5)) / sqrt(re)) * 0.5);
                      	end
                      	return tmp
                      end
                      
                      code[re_, im_] := If[LessEqual[re, -7e+146], N[(N[Sqrt[N[(-4.0 * re), $MachinePrecision]], $MachinePrecision] * 0.5), $MachinePrecision], If[LessEqual[re, -9e-125], N[(0.5 * N[Sqrt[N[(2.0 * N[(N[Sqrt[N[(im * im + N[(re * re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 2.1e-35], N[(N[Sqrt[N[(N[(-2.0 * re + im), $MachinePrecision] + im), $MachinePrecision]], $MachinePrecision] * 0.5), $MachinePrecision], N[(N[(N[(N[(N[Sqrt[2.0], $MachinePrecision] * im), $MachinePrecision] * N[Sqrt[0.5], $MachinePrecision]), $MachinePrecision] / N[Sqrt[re], $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision]]]]
                      
                      \begin{array}{l}
                      
                      \\
                      \begin{array}{l}
                      \mathbf{if}\;re \leq -7 \cdot 10^{+146}:\\
                      \;\;\;\;\sqrt{-4 \cdot re} \cdot 0.5\\
                      
                      \mathbf{elif}\;re \leq -9 \cdot 10^{-125}:\\
                      \;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(\sqrt{\mathsf{fma}\left(im, im, re \cdot re\right)} - re\right)}\\
                      
                      \mathbf{elif}\;re \leq 2.1 \cdot 10^{-35}:\\
                      \;\;\;\;\sqrt{\mathsf{fma}\left(-2, re, im\right) + im} \cdot 0.5\\
                      
                      \mathbf{else}:\\
                      \;\;\;\;\frac{\left(\sqrt{2} \cdot im\right) \cdot \sqrt{0.5}}{\sqrt{re}} \cdot 0.5\\
                      
                      
                      \end{array}
                      \end{array}
                      
                      Derivation
                      1. Split input into 4 regimes
                      2. if re < -7.0000000000000002e146

                        1. Initial program 4.2%

                          \[0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)} \]
                        2. Add Preprocessing
                        3. Step-by-step derivation
                          1. lift-*.f64N/A

                            \[\leadsto \color{blue}{\frac{1}{2} \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)}} \]
                          2. *-commutativeN/A

                            \[\leadsto \color{blue}{\sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)} \cdot \frac{1}{2}} \]
                          3. lower-*.f644.2

                            \[\leadsto \color{blue}{\sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)} \cdot 0.5} \]
                          4. lift-*.f64N/A

                            \[\leadsto \sqrt{\color{blue}{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)}} \cdot \frac{1}{2} \]
                          5. *-commutativeN/A

                            \[\leadsto \sqrt{\color{blue}{\left(\sqrt{re \cdot re + im \cdot im} - re\right) \cdot 2}} \cdot \frac{1}{2} \]
                          6. lower-*.f644.2

                            \[\leadsto \sqrt{\color{blue}{\left(\sqrt{re \cdot re + im \cdot im} - re\right) \cdot 2}} \cdot 0.5 \]
                          7. lift-sqrt.f64N/A

                            \[\leadsto \sqrt{\left(\color{blue}{\sqrt{re \cdot re + im \cdot im}} - re\right) \cdot 2} \cdot \frac{1}{2} \]
                          8. lift-+.f64N/A

                            \[\leadsto \sqrt{\left(\sqrt{\color{blue}{re \cdot re + im \cdot im}} - re\right) \cdot 2} \cdot \frac{1}{2} \]
                          9. +-commutativeN/A

                            \[\leadsto \sqrt{\left(\sqrt{\color{blue}{im \cdot im + re \cdot re}} - re\right) \cdot 2} \cdot \frac{1}{2} \]
                          10. lift-*.f64N/A

                            \[\leadsto \sqrt{\left(\sqrt{\color{blue}{im \cdot im} + re \cdot re} - re\right) \cdot 2} \cdot \frac{1}{2} \]
                          11. lift-*.f64N/A

                            \[\leadsto \sqrt{\left(\sqrt{im \cdot im + \color{blue}{re \cdot re}} - re\right) \cdot 2} \cdot \frac{1}{2} \]
                          12. lower-hypot.f64100.0

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

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

                          \[\leadsto \sqrt{\color{blue}{-4 \cdot re}} \cdot \frac{1}{2} \]
                        6. Step-by-step derivation
                          1. lower-*.f6484.4

                            \[\leadsto \sqrt{\color{blue}{-4 \cdot re}} \cdot 0.5 \]
                        7. Applied rewrites84.4%

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

                        if -7.0000000000000002e146 < re < -9.00000000000000024e-125

                        1. Initial program 79.6%

                          \[0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)} \]
                        2. Add Preprocessing
                        3. Step-by-step derivation
                          1. lift-+.f64N/A

                            \[\leadsto \frac{1}{2} \cdot \sqrt{2 \cdot \left(\sqrt{\color{blue}{re \cdot re + im \cdot im}} - re\right)} \]
                          2. +-commutativeN/A

                            \[\leadsto \frac{1}{2} \cdot \sqrt{2 \cdot \left(\sqrt{\color{blue}{im \cdot im + re \cdot re}} - re\right)} \]
                          3. lift-*.f64N/A

                            \[\leadsto \frac{1}{2} \cdot \sqrt{2 \cdot \left(\sqrt{\color{blue}{im \cdot im} + re \cdot re} - re\right)} \]
                          4. lower-fma.f6479.6

                            \[\leadsto 0.5 \cdot \sqrt{2 \cdot \left(\sqrt{\color{blue}{\mathsf{fma}\left(im, im, re \cdot re\right)}} - re\right)} \]
                        4. Applied rewrites79.6%

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

                        if -9.00000000000000024e-125 < re < 2.1e-35

                        1. Initial program 50.4%

                          \[0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)} \]
                        2. Add Preprocessing
                        3. Step-by-step derivation
                          1. lift-*.f64N/A

                            \[\leadsto \color{blue}{\frac{1}{2} \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)}} \]
                          2. *-commutativeN/A

                            \[\leadsto \color{blue}{\sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)} \cdot \frac{1}{2}} \]
                          3. lower-*.f6450.4

                            \[\leadsto \color{blue}{\sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)} \cdot 0.5} \]
                          4. lift-*.f64N/A

                            \[\leadsto \sqrt{\color{blue}{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)}} \cdot \frac{1}{2} \]
                          5. *-commutativeN/A

                            \[\leadsto \sqrt{\color{blue}{\left(\sqrt{re \cdot re + im \cdot im} - re\right) \cdot 2}} \cdot \frac{1}{2} \]
                          6. lower-*.f6450.4

                            \[\leadsto \sqrt{\color{blue}{\left(\sqrt{re \cdot re + im \cdot im} - re\right) \cdot 2}} \cdot 0.5 \]
                          7. lift-sqrt.f64N/A

                            \[\leadsto \sqrt{\left(\color{blue}{\sqrt{re \cdot re + im \cdot im}} - re\right) \cdot 2} \cdot \frac{1}{2} \]
                          8. lift-+.f64N/A

                            \[\leadsto \sqrt{\left(\sqrt{\color{blue}{re \cdot re + im \cdot im}} - re\right) \cdot 2} \cdot \frac{1}{2} \]
                          9. +-commutativeN/A

                            \[\leadsto \sqrt{\left(\sqrt{\color{blue}{im \cdot im + re \cdot re}} - re\right) \cdot 2} \cdot \frac{1}{2} \]
                          10. lift-*.f64N/A

                            \[\leadsto \sqrt{\left(\sqrt{\color{blue}{im \cdot im} + re \cdot re} - re\right) \cdot 2} \cdot \frac{1}{2} \]
                          11. lift-*.f64N/A

                            \[\leadsto \sqrt{\left(\sqrt{im \cdot im + \color{blue}{re \cdot re}} - re\right) \cdot 2} \cdot \frac{1}{2} \]
                          12. lower-hypot.f6490.7

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

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

                          \[\leadsto \sqrt{\color{blue}{2 \cdot im + re \cdot \left(\frac{re}{im} - 2\right)}} \cdot \frac{1}{2} \]
                        6. Step-by-step derivation
                          1. +-commutativeN/A

                            \[\leadsto \sqrt{\color{blue}{re \cdot \left(\frac{re}{im} - 2\right) + 2 \cdot im}} \cdot \frac{1}{2} \]
                          2. *-commutativeN/A

                            \[\leadsto \sqrt{\color{blue}{\left(\frac{re}{im} - 2\right) \cdot re} + 2 \cdot im} \cdot \frac{1}{2} \]
                          3. lower-fma.f64N/A

                            \[\leadsto \sqrt{\color{blue}{\mathsf{fma}\left(\frac{re}{im} - 2, re, 2 \cdot im\right)}} \cdot \frac{1}{2} \]
                          4. lower--.f64N/A

                            \[\leadsto \sqrt{\mathsf{fma}\left(\color{blue}{\frac{re}{im} - 2}, re, 2 \cdot im\right)} \cdot \frac{1}{2} \]
                          5. lower-/.f64N/A

                            \[\leadsto \sqrt{\mathsf{fma}\left(\color{blue}{\frac{re}{im}} - 2, re, 2 \cdot im\right)} \cdot \frac{1}{2} \]
                          6. lower-*.f6483.8

                            \[\leadsto \sqrt{\mathsf{fma}\left(\frac{re}{im} - 2, re, \color{blue}{2 \cdot im}\right)} \cdot 0.5 \]
                        7. Applied rewrites83.8%

                          \[\leadsto \sqrt{\color{blue}{\mathsf{fma}\left(\frac{re}{im} - 2, re, 2 \cdot im\right)}} \cdot 0.5 \]
                        8. Step-by-step derivation
                          1. Applied rewrites83.8%

                            \[\leadsto \sqrt{\mathsf{fma}\left(\frac{re}{im} - 2, re, im\right) + \color{blue}{im}} \cdot 0.5 \]
                          2. Taylor expanded in re around 0

                            \[\leadsto \sqrt{\left(im + -2 \cdot re\right) + im} \cdot \frac{1}{2} \]
                          3. Step-by-step derivation
                            1. Applied rewrites84.1%

                              \[\leadsto \sqrt{\mathsf{fma}\left(-2, re, im\right) + im} \cdot 0.5 \]

                            if 2.1e-35 < re

                            1. Initial program 10.5%

                              \[0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)} \]
                            2. Add Preprocessing
                            3. Step-by-step derivation
                              1. lift-*.f64N/A

                                \[\leadsto \color{blue}{\frac{1}{2} \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)}} \]
                              2. *-commutativeN/A

                                \[\leadsto \color{blue}{\sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)} \cdot \frac{1}{2}} \]
                              3. lower-*.f6410.5

                                \[\leadsto \color{blue}{\sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)} \cdot 0.5} \]
                              4. lift-*.f64N/A

                                \[\leadsto \sqrt{\color{blue}{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)}} \cdot \frac{1}{2} \]
                              5. *-commutativeN/A

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

                                \[\leadsto \sqrt{\color{blue}{\left(\sqrt{re \cdot re + im \cdot im} - re\right) \cdot 2}} \cdot 0.5 \]
                              7. lift-sqrt.f64N/A

                                \[\leadsto \sqrt{\left(\color{blue}{\sqrt{re \cdot re + im \cdot im}} - re\right) \cdot 2} \cdot \frac{1}{2} \]
                              8. lift-+.f64N/A

                                \[\leadsto \sqrt{\left(\sqrt{\color{blue}{re \cdot re + im \cdot im}} - re\right) \cdot 2} \cdot \frac{1}{2} \]
                              9. +-commutativeN/A

                                \[\leadsto \sqrt{\left(\sqrt{\color{blue}{im \cdot im + re \cdot re}} - re\right) \cdot 2} \cdot \frac{1}{2} \]
                              10. lift-*.f64N/A

                                \[\leadsto \sqrt{\left(\sqrt{\color{blue}{im \cdot im} + re \cdot re} - re\right) \cdot 2} \cdot \frac{1}{2} \]
                              11. lift-*.f64N/A

                                \[\leadsto \sqrt{\left(\sqrt{im \cdot im + \color{blue}{re \cdot re}} - re\right) \cdot 2} \cdot \frac{1}{2} \]
                              12. lower-hypot.f6438.4

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

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

                              \[\leadsto \color{blue}{\left(\left(im \cdot \left(\sqrt{\frac{1}{2}} \cdot \sqrt{2}\right)\right) \cdot \sqrt{\frac{1}{re}}\right)} \cdot \frac{1}{2} \]
                            6. Step-by-step derivation
                              1. *-commutativeN/A

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

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

                                \[\leadsto \color{blue}{\left(\left(\sqrt{\frac{1}{re}} \cdot \left(im \cdot \sqrt{\frac{1}{2}}\right)\right) \cdot \sqrt{2}\right)} \cdot \frac{1}{2} \]
                              4. lower-*.f64N/A

                                \[\leadsto \color{blue}{\left(\left(\sqrt{\frac{1}{re}} \cdot \left(im \cdot \sqrt{\frac{1}{2}}\right)\right) \cdot \sqrt{2}\right)} \cdot \frac{1}{2} \]
                              5. lower-*.f64N/A

                                \[\leadsto \left(\color{blue}{\left(\sqrt{\frac{1}{re}} \cdot \left(im \cdot \sqrt{\frac{1}{2}}\right)\right)} \cdot \sqrt{2}\right) \cdot \frac{1}{2} \]
                              6. lower-sqrt.f64N/A

                                \[\leadsto \left(\left(\color{blue}{\sqrt{\frac{1}{re}}} \cdot \left(im \cdot \sqrt{\frac{1}{2}}\right)\right) \cdot \sqrt{2}\right) \cdot \frac{1}{2} \]
                              7. lower-/.f64N/A

                                \[\leadsto \left(\left(\sqrt{\color{blue}{\frac{1}{re}}} \cdot \left(im \cdot \sqrt{\frac{1}{2}}\right)\right) \cdot \sqrt{2}\right) \cdot \frac{1}{2} \]
                              8. *-commutativeN/A

                                \[\leadsto \left(\left(\sqrt{\frac{1}{re}} \cdot \color{blue}{\left(\sqrt{\frac{1}{2}} \cdot im\right)}\right) \cdot \sqrt{2}\right) \cdot \frac{1}{2} \]
                              9. lower-*.f64N/A

                                \[\leadsto \left(\left(\sqrt{\frac{1}{re}} \cdot \color{blue}{\left(\sqrt{\frac{1}{2}} \cdot im\right)}\right) \cdot \sqrt{2}\right) \cdot \frac{1}{2} \]
                              10. lower-sqrt.f64N/A

                                \[\leadsto \left(\left(\sqrt{\frac{1}{re}} \cdot \left(\color{blue}{\sqrt{\frac{1}{2}}} \cdot im\right)\right) \cdot \sqrt{2}\right) \cdot \frac{1}{2} \]
                              11. lower-sqrt.f6475.6

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

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

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

                                  \[\leadsto \frac{\left(\sqrt{2} \cdot im\right) \cdot \sqrt{0.5}}{\sqrt{\color{blue}{re}}} \cdot 0.5 \]
                              3. Recombined 4 regimes into one program.
                              4. Add Preprocessing

                              Alternative 8: 78.4% accurate, 0.6× speedup?

                              \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;re \leq -7 \cdot 10^{+146}:\\ \;\;\;\;\sqrt{-4 \cdot re} \cdot 0.5\\ \mathbf{elif}\;re \leq -9 \cdot 10^{-125}:\\ \;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(\sqrt{\mathsf{fma}\left(im, im, re \cdot re\right)} - re\right)}\\ \mathbf{elif}\;re \leq 2.1 \cdot 10^{-35}:\\ \;\;\;\;\sqrt{\mathsf{fma}\left(-2, re, im\right) + im} \cdot 0.5\\ \mathbf{else}:\\ \;\;\;\;\left(\sqrt{2} \cdot \frac{\sqrt{0.5} \cdot im}{\sqrt{re}}\right) \cdot 0.5\\ \end{array} \end{array} \]
                              (FPCore (re im)
                               :precision binary64
                               (if (<= re -7e+146)
                                 (* (sqrt (* -4.0 re)) 0.5)
                                 (if (<= re -9e-125)
                                   (* 0.5 (sqrt (* 2.0 (- (sqrt (fma im im (* re re))) re))))
                                   (if (<= re 2.1e-35)
                                     (* (sqrt (+ (fma -2.0 re im) im)) 0.5)
                                     (* (* (sqrt 2.0) (/ (* (sqrt 0.5) im) (sqrt re))) 0.5)))))
                              double code(double re, double im) {
                              	double tmp;
                              	if (re <= -7e+146) {
                              		tmp = sqrt((-4.0 * re)) * 0.5;
                              	} else if (re <= -9e-125) {
                              		tmp = 0.5 * sqrt((2.0 * (sqrt(fma(im, im, (re * re))) - re)));
                              	} else if (re <= 2.1e-35) {
                              		tmp = sqrt((fma(-2.0, re, im) + im)) * 0.5;
                              	} else {
                              		tmp = (sqrt(2.0) * ((sqrt(0.5) * im) / sqrt(re))) * 0.5;
                              	}
                              	return tmp;
                              }
                              
                              function code(re, im)
                              	tmp = 0.0
                              	if (re <= -7e+146)
                              		tmp = Float64(sqrt(Float64(-4.0 * re)) * 0.5);
                              	elseif (re <= -9e-125)
                              		tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(sqrt(fma(im, im, Float64(re * re))) - re))));
                              	elseif (re <= 2.1e-35)
                              		tmp = Float64(sqrt(Float64(fma(-2.0, re, im) + im)) * 0.5);
                              	else
                              		tmp = Float64(Float64(sqrt(2.0) * Float64(Float64(sqrt(0.5) * im) / sqrt(re))) * 0.5);
                              	end
                              	return tmp
                              end
                              
                              code[re_, im_] := If[LessEqual[re, -7e+146], N[(N[Sqrt[N[(-4.0 * re), $MachinePrecision]], $MachinePrecision] * 0.5), $MachinePrecision], If[LessEqual[re, -9e-125], N[(0.5 * N[Sqrt[N[(2.0 * N[(N[Sqrt[N[(im * im + N[(re * re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 2.1e-35], N[(N[Sqrt[N[(N[(-2.0 * re + im), $MachinePrecision] + im), $MachinePrecision]], $MachinePrecision] * 0.5), $MachinePrecision], N[(N[(N[Sqrt[2.0], $MachinePrecision] * N[(N[(N[Sqrt[0.5], $MachinePrecision] * im), $MachinePrecision] / N[Sqrt[re], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision]]]]
                              
                              \begin{array}{l}
                              
                              \\
                              \begin{array}{l}
                              \mathbf{if}\;re \leq -7 \cdot 10^{+146}:\\
                              \;\;\;\;\sqrt{-4 \cdot re} \cdot 0.5\\
                              
                              \mathbf{elif}\;re \leq -9 \cdot 10^{-125}:\\
                              \;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(\sqrt{\mathsf{fma}\left(im, im, re \cdot re\right)} - re\right)}\\
                              
                              \mathbf{elif}\;re \leq 2.1 \cdot 10^{-35}:\\
                              \;\;\;\;\sqrt{\mathsf{fma}\left(-2, re, im\right) + im} \cdot 0.5\\
                              
                              \mathbf{else}:\\
                              \;\;\;\;\left(\sqrt{2} \cdot \frac{\sqrt{0.5} \cdot im}{\sqrt{re}}\right) \cdot 0.5\\
                              
                              
                              \end{array}
                              \end{array}
                              
                              Derivation
                              1. Split input into 4 regimes
                              2. if re < -7.0000000000000002e146

                                1. Initial program 4.2%

                                  \[0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)} \]
                                2. Add Preprocessing
                                3. Step-by-step derivation
                                  1. lift-*.f64N/A

                                    \[\leadsto \color{blue}{\frac{1}{2} \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)}} \]
                                  2. *-commutativeN/A

                                    \[\leadsto \color{blue}{\sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)} \cdot \frac{1}{2}} \]
                                  3. lower-*.f644.2

                                    \[\leadsto \color{blue}{\sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)} \cdot 0.5} \]
                                  4. lift-*.f64N/A

                                    \[\leadsto \sqrt{\color{blue}{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)}} \cdot \frac{1}{2} \]
                                  5. *-commutativeN/A

                                    \[\leadsto \sqrt{\color{blue}{\left(\sqrt{re \cdot re + im \cdot im} - re\right) \cdot 2}} \cdot \frac{1}{2} \]
                                  6. lower-*.f644.2

                                    \[\leadsto \sqrt{\color{blue}{\left(\sqrt{re \cdot re + im \cdot im} - re\right) \cdot 2}} \cdot 0.5 \]
                                  7. lift-sqrt.f64N/A

                                    \[\leadsto \sqrt{\left(\color{blue}{\sqrt{re \cdot re + im \cdot im}} - re\right) \cdot 2} \cdot \frac{1}{2} \]
                                  8. lift-+.f64N/A

                                    \[\leadsto \sqrt{\left(\sqrt{\color{blue}{re \cdot re + im \cdot im}} - re\right) \cdot 2} \cdot \frac{1}{2} \]
                                  9. +-commutativeN/A

                                    \[\leadsto \sqrt{\left(\sqrt{\color{blue}{im \cdot im + re \cdot re}} - re\right) \cdot 2} \cdot \frac{1}{2} \]
                                  10. lift-*.f64N/A

                                    \[\leadsto \sqrt{\left(\sqrt{\color{blue}{im \cdot im} + re \cdot re} - re\right) \cdot 2} \cdot \frac{1}{2} \]
                                  11. lift-*.f64N/A

                                    \[\leadsto \sqrt{\left(\sqrt{im \cdot im + \color{blue}{re \cdot re}} - re\right) \cdot 2} \cdot \frac{1}{2} \]
                                  12. lower-hypot.f64100.0

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

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

                                  \[\leadsto \sqrt{\color{blue}{-4 \cdot re}} \cdot \frac{1}{2} \]
                                6. Step-by-step derivation
                                  1. lower-*.f6484.4

                                    \[\leadsto \sqrt{\color{blue}{-4 \cdot re}} \cdot 0.5 \]
                                7. Applied rewrites84.4%

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

                                if -7.0000000000000002e146 < re < -9.00000000000000024e-125

                                1. Initial program 79.6%

                                  \[0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)} \]
                                2. Add Preprocessing
                                3. Step-by-step derivation
                                  1. lift-+.f64N/A

                                    \[\leadsto \frac{1}{2} \cdot \sqrt{2 \cdot \left(\sqrt{\color{blue}{re \cdot re + im \cdot im}} - re\right)} \]
                                  2. +-commutativeN/A

                                    \[\leadsto \frac{1}{2} \cdot \sqrt{2 \cdot \left(\sqrt{\color{blue}{im \cdot im + re \cdot re}} - re\right)} \]
                                  3. lift-*.f64N/A

                                    \[\leadsto \frac{1}{2} \cdot \sqrt{2 \cdot \left(\sqrt{\color{blue}{im \cdot im} + re \cdot re} - re\right)} \]
                                  4. lower-fma.f6479.6

                                    \[\leadsto 0.5 \cdot \sqrt{2 \cdot \left(\sqrt{\color{blue}{\mathsf{fma}\left(im, im, re \cdot re\right)}} - re\right)} \]
                                4. Applied rewrites79.6%

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

                                if -9.00000000000000024e-125 < re < 2.1e-35

                                1. Initial program 50.4%

                                  \[0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)} \]
                                2. Add Preprocessing
                                3. Step-by-step derivation
                                  1. lift-*.f64N/A

                                    \[\leadsto \color{blue}{\frac{1}{2} \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)}} \]
                                  2. *-commutativeN/A

                                    \[\leadsto \color{blue}{\sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)} \cdot \frac{1}{2}} \]
                                  3. lower-*.f6450.4

                                    \[\leadsto \color{blue}{\sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)} \cdot 0.5} \]
                                  4. lift-*.f64N/A

                                    \[\leadsto \sqrt{\color{blue}{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)}} \cdot \frac{1}{2} \]
                                  5. *-commutativeN/A

                                    \[\leadsto \sqrt{\color{blue}{\left(\sqrt{re \cdot re + im \cdot im} - re\right) \cdot 2}} \cdot \frac{1}{2} \]
                                  6. lower-*.f6450.4

                                    \[\leadsto \sqrt{\color{blue}{\left(\sqrt{re \cdot re + im \cdot im} - re\right) \cdot 2}} \cdot 0.5 \]
                                  7. lift-sqrt.f64N/A

                                    \[\leadsto \sqrt{\left(\color{blue}{\sqrt{re \cdot re + im \cdot im}} - re\right) \cdot 2} \cdot \frac{1}{2} \]
                                  8. lift-+.f64N/A

                                    \[\leadsto \sqrt{\left(\sqrt{\color{blue}{re \cdot re + im \cdot im}} - re\right) \cdot 2} \cdot \frac{1}{2} \]
                                  9. +-commutativeN/A

                                    \[\leadsto \sqrt{\left(\sqrt{\color{blue}{im \cdot im + re \cdot re}} - re\right) \cdot 2} \cdot \frac{1}{2} \]
                                  10. lift-*.f64N/A

                                    \[\leadsto \sqrt{\left(\sqrt{\color{blue}{im \cdot im} + re \cdot re} - re\right) \cdot 2} \cdot \frac{1}{2} \]
                                  11. lift-*.f64N/A

                                    \[\leadsto \sqrt{\left(\sqrt{im \cdot im + \color{blue}{re \cdot re}} - re\right) \cdot 2} \cdot \frac{1}{2} \]
                                  12. lower-hypot.f6490.7

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

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

                                  \[\leadsto \sqrt{\color{blue}{2 \cdot im + re \cdot \left(\frac{re}{im} - 2\right)}} \cdot \frac{1}{2} \]
                                6. Step-by-step derivation
                                  1. +-commutativeN/A

                                    \[\leadsto \sqrt{\color{blue}{re \cdot \left(\frac{re}{im} - 2\right) + 2 \cdot im}} \cdot \frac{1}{2} \]
                                  2. *-commutativeN/A

                                    \[\leadsto \sqrt{\color{blue}{\left(\frac{re}{im} - 2\right) \cdot re} + 2 \cdot im} \cdot \frac{1}{2} \]
                                  3. lower-fma.f64N/A

                                    \[\leadsto \sqrt{\color{blue}{\mathsf{fma}\left(\frac{re}{im} - 2, re, 2 \cdot im\right)}} \cdot \frac{1}{2} \]
                                  4. lower--.f64N/A

                                    \[\leadsto \sqrt{\mathsf{fma}\left(\color{blue}{\frac{re}{im} - 2}, re, 2 \cdot im\right)} \cdot \frac{1}{2} \]
                                  5. lower-/.f64N/A

                                    \[\leadsto \sqrt{\mathsf{fma}\left(\color{blue}{\frac{re}{im}} - 2, re, 2 \cdot im\right)} \cdot \frac{1}{2} \]
                                  6. lower-*.f6483.8

                                    \[\leadsto \sqrt{\mathsf{fma}\left(\frac{re}{im} - 2, re, \color{blue}{2 \cdot im}\right)} \cdot 0.5 \]
                                7. Applied rewrites83.8%

                                  \[\leadsto \sqrt{\color{blue}{\mathsf{fma}\left(\frac{re}{im} - 2, re, 2 \cdot im\right)}} \cdot 0.5 \]
                                8. Step-by-step derivation
                                  1. Applied rewrites83.8%

                                    \[\leadsto \sqrt{\mathsf{fma}\left(\frac{re}{im} - 2, re, im\right) + \color{blue}{im}} \cdot 0.5 \]
                                  2. Taylor expanded in re around 0

                                    \[\leadsto \sqrt{\left(im + -2 \cdot re\right) + im} \cdot \frac{1}{2} \]
                                  3. Step-by-step derivation
                                    1. Applied rewrites84.1%

                                      \[\leadsto \sqrt{\mathsf{fma}\left(-2, re, im\right) + im} \cdot 0.5 \]

                                    if 2.1e-35 < re

                                    1. Initial program 10.5%

                                      \[0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)} \]
                                    2. Add Preprocessing
                                    3. Step-by-step derivation
                                      1. lift-*.f64N/A

                                        \[\leadsto \color{blue}{\frac{1}{2} \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)}} \]
                                      2. *-commutativeN/A

                                        \[\leadsto \color{blue}{\sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)} \cdot \frac{1}{2}} \]
                                      3. lower-*.f6410.5

                                        \[\leadsto \color{blue}{\sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)} \cdot 0.5} \]
                                      4. lift-*.f64N/A

                                        \[\leadsto \sqrt{\color{blue}{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)}} \cdot \frac{1}{2} \]
                                      5. *-commutativeN/A

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

                                        \[\leadsto \sqrt{\color{blue}{\left(\sqrt{re \cdot re + im \cdot im} - re\right) \cdot 2}} \cdot 0.5 \]
                                      7. lift-sqrt.f64N/A

                                        \[\leadsto \sqrt{\left(\color{blue}{\sqrt{re \cdot re + im \cdot im}} - re\right) \cdot 2} \cdot \frac{1}{2} \]
                                      8. lift-+.f64N/A

                                        \[\leadsto \sqrt{\left(\sqrt{\color{blue}{re \cdot re + im \cdot im}} - re\right) \cdot 2} \cdot \frac{1}{2} \]
                                      9. +-commutativeN/A

                                        \[\leadsto \sqrt{\left(\sqrt{\color{blue}{im \cdot im + re \cdot re}} - re\right) \cdot 2} \cdot \frac{1}{2} \]
                                      10. lift-*.f64N/A

                                        \[\leadsto \sqrt{\left(\sqrt{\color{blue}{im \cdot im} + re \cdot re} - re\right) \cdot 2} \cdot \frac{1}{2} \]
                                      11. lift-*.f64N/A

                                        \[\leadsto \sqrt{\left(\sqrt{im \cdot im + \color{blue}{re \cdot re}} - re\right) \cdot 2} \cdot \frac{1}{2} \]
                                      12. lower-hypot.f6438.4

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

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

                                      \[\leadsto \color{blue}{\left(\left(im \cdot \left(\sqrt{\frac{1}{2}} \cdot \sqrt{2}\right)\right) \cdot \sqrt{\frac{1}{re}}\right)} \cdot \frac{1}{2} \]
                                    6. Step-by-step derivation
                                      1. *-commutativeN/A

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

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

                                        \[\leadsto \color{blue}{\left(\left(\sqrt{\frac{1}{re}} \cdot \left(im \cdot \sqrt{\frac{1}{2}}\right)\right) \cdot \sqrt{2}\right)} \cdot \frac{1}{2} \]
                                      4. lower-*.f64N/A

                                        \[\leadsto \color{blue}{\left(\left(\sqrt{\frac{1}{re}} \cdot \left(im \cdot \sqrt{\frac{1}{2}}\right)\right) \cdot \sqrt{2}\right)} \cdot \frac{1}{2} \]
                                      5. lower-*.f64N/A

                                        \[\leadsto \left(\color{blue}{\left(\sqrt{\frac{1}{re}} \cdot \left(im \cdot \sqrt{\frac{1}{2}}\right)\right)} \cdot \sqrt{2}\right) \cdot \frac{1}{2} \]
                                      6. lower-sqrt.f64N/A

                                        \[\leadsto \left(\left(\color{blue}{\sqrt{\frac{1}{re}}} \cdot \left(im \cdot \sqrt{\frac{1}{2}}\right)\right) \cdot \sqrt{2}\right) \cdot \frac{1}{2} \]
                                      7. lower-/.f64N/A

                                        \[\leadsto \left(\left(\sqrt{\color{blue}{\frac{1}{re}}} \cdot \left(im \cdot \sqrt{\frac{1}{2}}\right)\right) \cdot \sqrt{2}\right) \cdot \frac{1}{2} \]
                                      8. *-commutativeN/A

                                        \[\leadsto \left(\left(\sqrt{\frac{1}{re}} \cdot \color{blue}{\left(\sqrt{\frac{1}{2}} \cdot im\right)}\right) \cdot \sqrt{2}\right) \cdot \frac{1}{2} \]
                                      9. lower-*.f64N/A

                                        \[\leadsto \left(\left(\sqrt{\frac{1}{re}} \cdot \color{blue}{\left(\sqrt{\frac{1}{2}} \cdot im\right)}\right) \cdot \sqrt{2}\right) \cdot \frac{1}{2} \]
                                      10. lower-sqrt.f64N/A

                                        \[\leadsto \left(\left(\sqrt{\frac{1}{re}} \cdot \left(\color{blue}{\sqrt{\frac{1}{2}}} \cdot im\right)\right) \cdot \sqrt{2}\right) \cdot \frac{1}{2} \]
                                      11. lower-sqrt.f6475.6

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

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

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

                                          \[\leadsto \left(\sqrt{2} \cdot \color{blue}{\frac{\sqrt{0.5} \cdot im}{\sqrt{re}}}\right) \cdot 0.5 \]
                                      3. Recombined 4 regimes into one program.
                                      4. Add Preprocessing

                                      Alternative 9: 72.9% accurate, 0.7× speedup?

                                      \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;re \leq -7 \cdot 10^{+146}:\\ \;\;\;\;\sqrt{-4 \cdot re} \cdot 0.5\\ \mathbf{elif}\;re \leq -6.5 \cdot 10^{-89}:\\ \;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(\sqrt{\mathsf{fma}\left(im, im, re \cdot re\right)} - re\right)}\\ \mathbf{elif}\;re \leq 3.9 \cdot 10^{+135}:\\ \;\;\;\;\sqrt{\mathsf{fma}\left(\frac{re}{im} - 2, re, im\right) + im} \cdot 0.5\\ \mathbf{else}:\\ \;\;\;\;\left(0.5 \cdot \sqrt{2}\right) \cdot \sqrt{\left(\frac{im}{re} \cdot im\right) \cdot 0.5}\\ \end{array} \end{array} \]
                                      (FPCore (re im)
                                       :precision binary64
                                       (if (<= re -7e+146)
                                         (* (sqrt (* -4.0 re)) 0.5)
                                         (if (<= re -6.5e-89)
                                           (* 0.5 (sqrt (* 2.0 (- (sqrt (fma im im (* re re))) re))))
                                           (if (<= re 3.9e+135)
                                             (* (sqrt (+ (fma (- (/ re im) 2.0) re im) im)) 0.5)
                                             (* (* 0.5 (sqrt 2.0)) (sqrt (* (* (/ im re) im) 0.5)))))))
                                      double code(double re, double im) {
                                      	double tmp;
                                      	if (re <= -7e+146) {
                                      		tmp = sqrt((-4.0 * re)) * 0.5;
                                      	} else if (re <= -6.5e-89) {
                                      		tmp = 0.5 * sqrt((2.0 * (sqrt(fma(im, im, (re * re))) - re)));
                                      	} else if (re <= 3.9e+135) {
                                      		tmp = sqrt((fma(((re / im) - 2.0), re, im) + im)) * 0.5;
                                      	} else {
                                      		tmp = (0.5 * sqrt(2.0)) * sqrt((((im / re) * im) * 0.5));
                                      	}
                                      	return tmp;
                                      }
                                      
                                      function code(re, im)
                                      	tmp = 0.0
                                      	if (re <= -7e+146)
                                      		tmp = Float64(sqrt(Float64(-4.0 * re)) * 0.5);
                                      	elseif (re <= -6.5e-89)
                                      		tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(sqrt(fma(im, im, Float64(re * re))) - re))));
                                      	elseif (re <= 3.9e+135)
                                      		tmp = Float64(sqrt(Float64(fma(Float64(Float64(re / im) - 2.0), re, im) + im)) * 0.5);
                                      	else
                                      		tmp = Float64(Float64(0.5 * sqrt(2.0)) * sqrt(Float64(Float64(Float64(im / re) * im) * 0.5)));
                                      	end
                                      	return tmp
                                      end
                                      
                                      code[re_, im_] := If[LessEqual[re, -7e+146], N[(N[Sqrt[N[(-4.0 * re), $MachinePrecision]], $MachinePrecision] * 0.5), $MachinePrecision], If[LessEqual[re, -6.5e-89], N[(0.5 * N[Sqrt[N[(2.0 * N[(N[Sqrt[N[(im * im + N[(re * re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 3.9e+135], N[(N[Sqrt[N[(N[(N[(N[(re / im), $MachinePrecision] - 2.0), $MachinePrecision] * re + im), $MachinePrecision] + im), $MachinePrecision]], $MachinePrecision] * 0.5), $MachinePrecision], N[(N[(0.5 * N[Sqrt[2.0], $MachinePrecision]), $MachinePrecision] * N[Sqrt[N[(N[(N[(im / re), $MachinePrecision] * im), $MachinePrecision] * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]]
                                      
                                      \begin{array}{l}
                                      
                                      \\
                                      \begin{array}{l}
                                      \mathbf{if}\;re \leq -7 \cdot 10^{+146}:\\
                                      \;\;\;\;\sqrt{-4 \cdot re} \cdot 0.5\\
                                      
                                      \mathbf{elif}\;re \leq -6.5 \cdot 10^{-89}:\\
                                      \;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(\sqrt{\mathsf{fma}\left(im, im, re \cdot re\right)} - re\right)}\\
                                      
                                      \mathbf{elif}\;re \leq 3.9 \cdot 10^{+135}:\\
                                      \;\;\;\;\sqrt{\mathsf{fma}\left(\frac{re}{im} - 2, re, im\right) + im} \cdot 0.5\\
                                      
                                      \mathbf{else}:\\
                                      \;\;\;\;\left(0.5 \cdot \sqrt{2}\right) \cdot \sqrt{\left(\frac{im}{re} \cdot im\right) \cdot 0.5}\\
                                      
                                      
                                      \end{array}
                                      \end{array}
                                      
                                      Derivation
                                      1. Split input into 4 regimes
                                      2. if re < -7.0000000000000002e146

                                        1. Initial program 4.2%

                                          \[0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)} \]
                                        2. Add Preprocessing
                                        3. Step-by-step derivation
                                          1. lift-*.f64N/A

                                            \[\leadsto \color{blue}{\frac{1}{2} \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)}} \]
                                          2. *-commutativeN/A

                                            \[\leadsto \color{blue}{\sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)} \cdot \frac{1}{2}} \]
                                          3. lower-*.f644.2

                                            \[\leadsto \color{blue}{\sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)} \cdot 0.5} \]
                                          4. lift-*.f64N/A

                                            \[\leadsto \sqrt{\color{blue}{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)}} \cdot \frac{1}{2} \]
                                          5. *-commutativeN/A

                                            \[\leadsto \sqrt{\color{blue}{\left(\sqrt{re \cdot re + im \cdot im} - re\right) \cdot 2}} \cdot \frac{1}{2} \]
                                          6. lower-*.f644.2

                                            \[\leadsto \sqrt{\color{blue}{\left(\sqrt{re \cdot re + im \cdot im} - re\right) \cdot 2}} \cdot 0.5 \]
                                          7. lift-sqrt.f64N/A

                                            \[\leadsto \sqrt{\left(\color{blue}{\sqrt{re \cdot re + im \cdot im}} - re\right) \cdot 2} \cdot \frac{1}{2} \]
                                          8. lift-+.f64N/A

                                            \[\leadsto \sqrt{\left(\sqrt{\color{blue}{re \cdot re + im \cdot im}} - re\right) \cdot 2} \cdot \frac{1}{2} \]
                                          9. +-commutativeN/A

                                            \[\leadsto \sqrt{\left(\sqrt{\color{blue}{im \cdot im + re \cdot re}} - re\right) \cdot 2} \cdot \frac{1}{2} \]
                                          10. lift-*.f64N/A

                                            \[\leadsto \sqrt{\left(\sqrt{\color{blue}{im \cdot im} + re \cdot re} - re\right) \cdot 2} \cdot \frac{1}{2} \]
                                          11. lift-*.f64N/A

                                            \[\leadsto \sqrt{\left(\sqrt{im \cdot im + \color{blue}{re \cdot re}} - re\right) \cdot 2} \cdot \frac{1}{2} \]
                                          12. lower-hypot.f64100.0

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

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

                                          \[\leadsto \sqrt{\color{blue}{-4 \cdot re}} \cdot \frac{1}{2} \]
                                        6. Step-by-step derivation
                                          1. lower-*.f6484.4

                                            \[\leadsto \sqrt{\color{blue}{-4 \cdot re}} \cdot 0.5 \]
                                        7. Applied rewrites84.4%

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

                                        if -7.0000000000000002e146 < re < -6.50000000000000034e-89

                                        1. Initial program 78.1%

                                          \[0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)} \]
                                        2. Add Preprocessing
                                        3. Step-by-step derivation
                                          1. lift-+.f64N/A

                                            \[\leadsto \frac{1}{2} \cdot \sqrt{2 \cdot \left(\sqrt{\color{blue}{re \cdot re + im \cdot im}} - re\right)} \]
                                          2. +-commutativeN/A

                                            \[\leadsto \frac{1}{2} \cdot \sqrt{2 \cdot \left(\sqrt{\color{blue}{im \cdot im + re \cdot re}} - re\right)} \]
                                          3. lift-*.f64N/A

                                            \[\leadsto \frac{1}{2} \cdot \sqrt{2 \cdot \left(\sqrt{\color{blue}{im \cdot im} + re \cdot re} - re\right)} \]
                                          4. lower-fma.f6478.1

                                            \[\leadsto 0.5 \cdot \sqrt{2 \cdot \left(\sqrt{\color{blue}{\mathsf{fma}\left(im, im, re \cdot re\right)}} - re\right)} \]
                                        4. Applied rewrites78.1%

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

                                        if -6.50000000000000034e-89 < re < 3.90000000000000032e135

                                        1. Initial program 46.1%

                                          \[0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)} \]
                                        2. Add Preprocessing
                                        3. Step-by-step derivation
                                          1. lift-*.f64N/A

                                            \[\leadsto \color{blue}{\frac{1}{2} \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)}} \]
                                          2. *-commutativeN/A

                                            \[\leadsto \color{blue}{\sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)} \cdot \frac{1}{2}} \]
                                          3. lower-*.f6446.1

                                            \[\leadsto \color{blue}{\sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)} \cdot 0.5} \]
                                          4. lift-*.f64N/A

                                            \[\leadsto \sqrt{\color{blue}{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)}} \cdot \frac{1}{2} \]
                                          5. *-commutativeN/A

                                            \[\leadsto \sqrt{\color{blue}{\left(\sqrt{re \cdot re + im \cdot im} - re\right) \cdot 2}} \cdot \frac{1}{2} \]
                                          6. lower-*.f6446.1

                                            \[\leadsto \sqrt{\color{blue}{\left(\sqrt{re \cdot re + im \cdot im} - re\right) \cdot 2}} \cdot 0.5 \]
                                          7. lift-sqrt.f64N/A

                                            \[\leadsto \sqrt{\left(\color{blue}{\sqrt{re \cdot re + im \cdot im}} - re\right) \cdot 2} \cdot \frac{1}{2} \]
                                          8. lift-+.f64N/A

                                            \[\leadsto \sqrt{\left(\sqrt{\color{blue}{re \cdot re + im \cdot im}} - re\right) \cdot 2} \cdot \frac{1}{2} \]
                                          9. +-commutativeN/A

                                            \[\leadsto \sqrt{\left(\sqrt{\color{blue}{im \cdot im + re \cdot re}} - re\right) \cdot 2} \cdot \frac{1}{2} \]
                                          10. lift-*.f64N/A

                                            \[\leadsto \sqrt{\left(\sqrt{\color{blue}{im \cdot im} + re \cdot re} - re\right) \cdot 2} \cdot \frac{1}{2} \]
                                          11. lift-*.f64N/A

                                            \[\leadsto \sqrt{\left(\sqrt{im \cdot im + \color{blue}{re \cdot re}} - re\right) \cdot 2} \cdot \frac{1}{2} \]
                                          12. lower-hypot.f6481.9

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

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

                                          \[\leadsto \sqrt{\color{blue}{2 \cdot im + re \cdot \left(\frac{re}{im} - 2\right)}} \cdot \frac{1}{2} \]
                                        6. Step-by-step derivation
                                          1. +-commutativeN/A

                                            \[\leadsto \sqrt{\color{blue}{re \cdot \left(\frac{re}{im} - 2\right) + 2 \cdot im}} \cdot \frac{1}{2} \]
                                          2. *-commutativeN/A

                                            \[\leadsto \sqrt{\color{blue}{\left(\frac{re}{im} - 2\right) \cdot re} + 2 \cdot im} \cdot \frac{1}{2} \]
                                          3. lower-fma.f64N/A

                                            \[\leadsto \sqrt{\color{blue}{\mathsf{fma}\left(\frac{re}{im} - 2, re, 2 \cdot im\right)}} \cdot \frac{1}{2} \]
                                          4. lower--.f64N/A

                                            \[\leadsto \sqrt{\mathsf{fma}\left(\color{blue}{\frac{re}{im} - 2}, re, 2 \cdot im\right)} \cdot \frac{1}{2} \]
                                          5. lower-/.f64N/A

                                            \[\leadsto \sqrt{\mathsf{fma}\left(\color{blue}{\frac{re}{im}} - 2, re, 2 \cdot im\right)} \cdot \frac{1}{2} \]
                                          6. lower-*.f6475.4

                                            \[\leadsto \sqrt{\mathsf{fma}\left(\frac{re}{im} - 2, re, \color{blue}{2 \cdot im}\right)} \cdot 0.5 \]
                                        7. Applied rewrites75.4%

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

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

                                          if 3.90000000000000032e135 < re

                                          1. Initial program 5.3%

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

                                            \[\leadsto \frac{1}{2} \cdot \sqrt{2 \cdot \color{blue}{\left(im + -1 \cdot re\right)}} \]
                                          4. Step-by-step derivation
                                            1. fp-cancel-sign-sub-invN/A

                                              \[\leadsto \frac{1}{2} \cdot \sqrt{2 \cdot \color{blue}{\left(im - \left(\mathsf{neg}\left(-1\right)\right) \cdot re\right)}} \]
                                            2. metadata-evalN/A

                                              \[\leadsto \frac{1}{2} \cdot \sqrt{2 \cdot \left(im - \color{blue}{1} \cdot re\right)} \]
                                            3. *-lft-identityN/A

                                              \[\leadsto \frac{1}{2} \cdot \sqrt{2 \cdot \left(im - \color{blue}{re}\right)} \]
                                            4. lower--.f6415.2

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

                                            \[\leadsto 0.5 \cdot \sqrt{2 \cdot \color{blue}{\left(im - re\right)}} \]
                                          6. Step-by-step derivation
                                            1. lift-*.f64N/A

                                              \[\leadsto \color{blue}{\frac{1}{2} \cdot \sqrt{2 \cdot \left(im - re\right)}} \]
                                            2. lift-sqrt.f64N/A

                                              \[\leadsto \frac{1}{2} \cdot \color{blue}{\sqrt{2 \cdot \left(im - re\right)}} \]
                                            3. lift-*.f64N/A

                                              \[\leadsto \frac{1}{2} \cdot \sqrt{\color{blue}{2 \cdot \left(im - re\right)}} \]
                                            4. sqrt-prodN/A

                                              \[\leadsto \frac{1}{2} \cdot \color{blue}{\left(\sqrt{2} \cdot \sqrt{im - re}\right)} \]
                                            5. lift-sqrt.f64N/A

                                              \[\leadsto \frac{1}{2} \cdot \left(\color{blue}{\sqrt{2}} \cdot \sqrt{im - re}\right) \]
                                            6. pow1/2N/A

                                              \[\leadsto \frac{1}{2} \cdot \left(\sqrt{2} \cdot \color{blue}{{\left(im - re\right)}^{\frac{1}{2}}}\right) \]
                                            7. associate-*r*N/A

                                              \[\leadsto \color{blue}{\left(\frac{1}{2} \cdot \sqrt{2}\right) \cdot {\left(im - re\right)}^{\frac{1}{2}}} \]
                                            8. lower-*.f64N/A

                                              \[\leadsto \color{blue}{\left(\frac{1}{2} \cdot \sqrt{2}\right) \cdot {\left(im - re\right)}^{\frac{1}{2}}} \]
                                            9. lower-*.f64N/A

                                              \[\leadsto \color{blue}{\left(\frac{1}{2} \cdot \sqrt{2}\right)} \cdot {\left(im - re\right)}^{\frac{1}{2}} \]
                                            10. pow1/2N/A

                                              \[\leadsto \left(\frac{1}{2} \cdot \sqrt{2}\right) \cdot \color{blue}{\sqrt{im - re}} \]
                                            11. lower-sqrt.f6415.1

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

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

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

                                              \[\leadsto \left(\frac{1}{2} \cdot \sqrt{2}\right) \cdot \sqrt{\color{blue}{\frac{{im}^{2}}{re} \cdot \frac{1}{2}}} \]
                                            2. lower-*.f64N/A

                                              \[\leadsto \left(\frac{1}{2} \cdot \sqrt{2}\right) \cdot \sqrt{\color{blue}{\frac{{im}^{2}}{re} \cdot \frac{1}{2}}} \]
                                            3. lower-/.f64N/A

                                              \[\leadsto \left(\frac{1}{2} \cdot \sqrt{2}\right) \cdot \sqrt{\color{blue}{\frac{{im}^{2}}{re}} \cdot \frac{1}{2}} \]
                                            4. unpow2N/A

                                              \[\leadsto \left(\frac{1}{2} \cdot \sqrt{2}\right) \cdot \sqrt{\frac{\color{blue}{im \cdot im}}{re} \cdot \frac{1}{2}} \]
                                            5. lower-*.f6458.9

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

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

                                              \[\leadsto \left(0.5 \cdot \sqrt{2}\right) \cdot \sqrt{\left(\frac{im}{re} \cdot im\right) \cdot 0.5} \]
                                          12. Recombined 4 regimes into one program.
                                          13. Add Preprocessing

                                          Alternative 10: 68.7% accurate, 0.9× speedup?

                                          \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;re \leq -0.00024:\\ \;\;\;\;\sqrt{-4 \cdot re} \cdot 0.5\\ \mathbf{elif}\;re \leq 3.9 \cdot 10^{+135}:\\ \;\;\;\;\sqrt{\mathsf{fma}\left(\frac{re}{im} - 2, re, im\right) + im} \cdot 0.5\\ \mathbf{else}:\\ \;\;\;\;\sqrt{\frac{im \cdot im}{re}} \cdot 0.5\\ \end{array} \end{array} \]
                                          (FPCore (re im)
                                           :precision binary64
                                           (if (<= re -0.00024)
                                             (* (sqrt (* -4.0 re)) 0.5)
                                             (if (<= re 3.9e+135)
                                               (* (sqrt (+ (fma (- (/ re im) 2.0) re im) im)) 0.5)
                                               (* (sqrt (/ (* im im) re)) 0.5))))
                                          double code(double re, double im) {
                                          	double tmp;
                                          	if (re <= -0.00024) {
                                          		tmp = sqrt((-4.0 * re)) * 0.5;
                                          	} else if (re <= 3.9e+135) {
                                          		tmp = sqrt((fma(((re / im) - 2.0), re, im) + im)) * 0.5;
                                          	} else {
                                          		tmp = sqrt(((im * im) / re)) * 0.5;
                                          	}
                                          	return tmp;
                                          }
                                          
                                          function code(re, im)
                                          	tmp = 0.0
                                          	if (re <= -0.00024)
                                          		tmp = Float64(sqrt(Float64(-4.0 * re)) * 0.5);
                                          	elseif (re <= 3.9e+135)
                                          		tmp = Float64(sqrt(Float64(fma(Float64(Float64(re / im) - 2.0), re, im) + im)) * 0.5);
                                          	else
                                          		tmp = Float64(sqrt(Float64(Float64(im * im) / re)) * 0.5);
                                          	end
                                          	return tmp
                                          end
                                          
                                          code[re_, im_] := If[LessEqual[re, -0.00024], N[(N[Sqrt[N[(-4.0 * re), $MachinePrecision]], $MachinePrecision] * 0.5), $MachinePrecision], If[LessEqual[re, 3.9e+135], N[(N[Sqrt[N[(N[(N[(N[(re / im), $MachinePrecision] - 2.0), $MachinePrecision] * re + im), $MachinePrecision] + im), $MachinePrecision]], $MachinePrecision] * 0.5), $MachinePrecision], N[(N[Sqrt[N[(N[(im * im), $MachinePrecision] / re), $MachinePrecision]], $MachinePrecision] * 0.5), $MachinePrecision]]]
                                          
                                          \begin{array}{l}
                                          
                                          \\
                                          \begin{array}{l}
                                          \mathbf{if}\;re \leq -0.00024:\\
                                          \;\;\;\;\sqrt{-4 \cdot re} \cdot 0.5\\
                                          
                                          \mathbf{elif}\;re \leq 3.9 \cdot 10^{+135}:\\
                                          \;\;\;\;\sqrt{\mathsf{fma}\left(\frac{re}{im} - 2, re, im\right) + im} \cdot 0.5\\
                                          
                                          \mathbf{else}:\\
                                          \;\;\;\;\sqrt{\frac{im \cdot im}{re}} \cdot 0.5\\
                                          
                                          
                                          \end{array}
                                          \end{array}
                                          
                                          Derivation
                                          1. Split input into 3 regimes
                                          2. if re < -2.40000000000000006e-4

                                            1. Initial program 50.4%

                                              \[0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)} \]
                                            2. Add Preprocessing
                                            3. Step-by-step derivation
                                              1. lift-*.f64N/A

                                                \[\leadsto \color{blue}{\frac{1}{2} \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)}} \]
                                              2. *-commutativeN/A

                                                \[\leadsto \color{blue}{\sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)} \cdot \frac{1}{2}} \]
                                              3. lower-*.f6450.4

                                                \[\leadsto \color{blue}{\sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)} \cdot 0.5} \]
                                              4. lift-*.f64N/A

                                                \[\leadsto \sqrt{\color{blue}{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)}} \cdot \frac{1}{2} \]
                                              5. *-commutativeN/A

                                                \[\leadsto \sqrt{\color{blue}{\left(\sqrt{re \cdot re + im \cdot im} - re\right) \cdot 2}} \cdot \frac{1}{2} \]
                                              6. lower-*.f6450.4

                                                \[\leadsto \sqrt{\color{blue}{\left(\sqrt{re \cdot re + im \cdot im} - re\right) \cdot 2}} \cdot 0.5 \]
                                              7. lift-sqrt.f64N/A

                                                \[\leadsto \sqrt{\left(\color{blue}{\sqrt{re \cdot re + im \cdot im}} - re\right) \cdot 2} \cdot \frac{1}{2} \]
                                              8. lift-+.f64N/A

                                                \[\leadsto \sqrt{\left(\sqrt{\color{blue}{re \cdot re + im \cdot im}} - re\right) \cdot 2} \cdot \frac{1}{2} \]
                                              9. +-commutativeN/A

                                                \[\leadsto \sqrt{\left(\sqrt{\color{blue}{im \cdot im + re \cdot re}} - re\right) \cdot 2} \cdot \frac{1}{2} \]
                                              10. lift-*.f64N/A

                                                \[\leadsto \sqrt{\left(\sqrt{\color{blue}{im \cdot im} + re \cdot re} - re\right) \cdot 2} \cdot \frac{1}{2} \]
                                              11. lift-*.f64N/A

                                                \[\leadsto \sqrt{\left(\sqrt{im \cdot im + \color{blue}{re \cdot re}} - re\right) \cdot 2} \cdot \frac{1}{2} \]
                                              12. lower-hypot.f64100.0

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

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

                                              \[\leadsto \sqrt{\color{blue}{-4 \cdot re}} \cdot \frac{1}{2} \]
                                            6. Step-by-step derivation
                                              1. lower-*.f6477.7

                                                \[\leadsto \sqrt{\color{blue}{-4 \cdot re}} \cdot 0.5 \]
                                            7. Applied rewrites77.7%

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

                                            if -2.40000000000000006e-4 < re < 3.90000000000000032e135

                                            1. Initial program 50.1%

                                              \[0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)} \]
                                            2. Add Preprocessing
                                            3. Step-by-step derivation
                                              1. lift-*.f64N/A

                                                \[\leadsto \color{blue}{\frac{1}{2} \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)}} \]
                                              2. *-commutativeN/A

                                                \[\leadsto \color{blue}{\sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)} \cdot \frac{1}{2}} \]
                                              3. lower-*.f6450.1

                                                \[\leadsto \color{blue}{\sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)} \cdot 0.5} \]
                                              4. lift-*.f64N/A

                                                \[\leadsto \sqrt{\color{blue}{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)}} \cdot \frac{1}{2} \]
                                              5. *-commutativeN/A

                                                \[\leadsto \sqrt{\color{blue}{\left(\sqrt{re \cdot re + im \cdot im} - re\right) \cdot 2}} \cdot \frac{1}{2} \]
                                              6. lower-*.f6450.1

                                                \[\leadsto \sqrt{\color{blue}{\left(\sqrt{re \cdot re + im \cdot im} - re\right) \cdot 2}} \cdot 0.5 \]
                                              7. lift-sqrt.f64N/A

                                                \[\leadsto \sqrt{\left(\color{blue}{\sqrt{re \cdot re + im \cdot im}} - re\right) \cdot 2} \cdot \frac{1}{2} \]
                                              8. lift-+.f64N/A

                                                \[\leadsto \sqrt{\left(\sqrt{\color{blue}{re \cdot re + im \cdot im}} - re\right) \cdot 2} \cdot \frac{1}{2} \]
                                              9. +-commutativeN/A

                                                \[\leadsto \sqrt{\left(\sqrt{\color{blue}{im \cdot im + re \cdot re}} - re\right) \cdot 2} \cdot \frac{1}{2} \]
                                              10. lift-*.f64N/A

                                                \[\leadsto \sqrt{\left(\sqrt{\color{blue}{im \cdot im} + re \cdot re} - re\right) \cdot 2} \cdot \frac{1}{2} \]
                                              11. lift-*.f64N/A

                                                \[\leadsto \sqrt{\left(\sqrt{im \cdot im + \color{blue}{re \cdot re}} - re\right) \cdot 2} \cdot \frac{1}{2} \]
                                              12. lower-hypot.f6484.7

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

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

                                              \[\leadsto \sqrt{\color{blue}{2 \cdot im + re \cdot \left(\frac{re}{im} - 2\right)}} \cdot \frac{1}{2} \]
                                            6. Step-by-step derivation
                                              1. +-commutativeN/A

                                                \[\leadsto \sqrt{\color{blue}{re \cdot \left(\frac{re}{im} - 2\right) + 2 \cdot im}} \cdot \frac{1}{2} \]
                                              2. *-commutativeN/A

                                                \[\leadsto \sqrt{\color{blue}{\left(\frac{re}{im} - 2\right) \cdot re} + 2 \cdot im} \cdot \frac{1}{2} \]
                                              3. lower-fma.f64N/A

                                                \[\leadsto \sqrt{\color{blue}{\mathsf{fma}\left(\frac{re}{im} - 2, re, 2 \cdot im\right)}} \cdot \frac{1}{2} \]
                                              4. lower--.f64N/A

                                                \[\leadsto \sqrt{\mathsf{fma}\left(\color{blue}{\frac{re}{im} - 2}, re, 2 \cdot im\right)} \cdot \frac{1}{2} \]
                                              5. lower-/.f64N/A

                                                \[\leadsto \sqrt{\mathsf{fma}\left(\color{blue}{\frac{re}{im}} - 2, re, 2 \cdot im\right)} \cdot \frac{1}{2} \]
                                              6. lower-*.f6473.8

                                                \[\leadsto \sqrt{\mathsf{fma}\left(\frac{re}{im} - 2, re, \color{blue}{2 \cdot im}\right)} \cdot 0.5 \]
                                            7. Applied rewrites73.8%

                                              \[\leadsto \sqrt{\color{blue}{\mathsf{fma}\left(\frac{re}{im} - 2, re, 2 \cdot im\right)}} \cdot 0.5 \]
                                            8. Step-by-step derivation
                                              1. Applied rewrites73.8%

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

                                              if 3.90000000000000032e135 < re

                                              1. Initial program 5.3%

                                                \[0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)} \]
                                              2. Add Preprocessing
                                              3. Step-by-step derivation
                                                1. lift-*.f64N/A

                                                  \[\leadsto \color{blue}{\frac{1}{2} \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)}} \]
                                                2. *-commutativeN/A

                                                  \[\leadsto \color{blue}{\sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)} \cdot \frac{1}{2}} \]
                                                3. lower-*.f645.3

                                                  \[\leadsto \color{blue}{\sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)} \cdot 0.5} \]
                                                4. lift-*.f64N/A

                                                  \[\leadsto \sqrt{\color{blue}{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)}} \cdot \frac{1}{2} \]
                                                5. *-commutativeN/A

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

                                                  \[\leadsto \sqrt{\color{blue}{\left(\sqrt{re \cdot re + im \cdot im} - re\right) \cdot 2}} \cdot 0.5 \]
                                                7. lift-sqrt.f64N/A

                                                  \[\leadsto \sqrt{\left(\color{blue}{\sqrt{re \cdot re + im \cdot im}} - re\right) \cdot 2} \cdot \frac{1}{2} \]
                                                8. lift-+.f64N/A

                                                  \[\leadsto \sqrt{\left(\sqrt{\color{blue}{re \cdot re + im \cdot im}} - re\right) \cdot 2} \cdot \frac{1}{2} \]
                                                9. +-commutativeN/A

                                                  \[\leadsto \sqrt{\left(\sqrt{\color{blue}{im \cdot im + re \cdot re}} - re\right) \cdot 2} \cdot \frac{1}{2} \]
                                                10. lift-*.f64N/A

                                                  \[\leadsto \sqrt{\left(\sqrt{\color{blue}{im \cdot im} + re \cdot re} - re\right) \cdot 2} \cdot \frac{1}{2} \]
                                                11. lift-*.f64N/A

                                                  \[\leadsto \sqrt{\left(\sqrt{im \cdot im + \color{blue}{re \cdot re}} - re\right) \cdot 2} \cdot \frac{1}{2} \]
                                                12. lower-hypot.f6431.9

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

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

                                                \[\leadsto \sqrt{\color{blue}{\frac{{im}^{2}}{re}}} \cdot \frac{1}{2} \]
                                              6. Step-by-step derivation
                                                1. lower-/.f64N/A

                                                  \[\leadsto \sqrt{\color{blue}{\frac{{im}^{2}}{re}}} \cdot \frac{1}{2} \]
                                                2. unpow2N/A

                                                  \[\leadsto \sqrt{\frac{\color{blue}{im \cdot im}}{re}} \cdot \frac{1}{2} \]
                                                3. lower-*.f6459.2

                                                  \[\leadsto \sqrt{\frac{\color{blue}{im \cdot im}}{re}} \cdot 0.5 \]
                                              7. Applied rewrites59.2%

                                                \[\leadsto \sqrt{\color{blue}{\frac{im \cdot im}{re}}} \cdot 0.5 \]
                                            9. Recombined 3 regimes into one program.
                                            10. Add Preprocessing

                                            Alternative 11: 68.0% accurate, 1.1× speedup?

                                            \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;re \leq -0.00029:\\ \;\;\;\;\sqrt{-4 \cdot re} \cdot 0.5\\ \mathbf{elif}\;re \leq 1.5 \cdot 10^{-30}:\\ \;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(im - re\right)}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{\frac{im \cdot im}{re}} \cdot 0.5\\ \end{array} \end{array} \]
                                            (FPCore (re im)
                                             :precision binary64
                                             (if (<= re -0.00029)
                                               (* (sqrt (* -4.0 re)) 0.5)
                                               (if (<= re 1.5e-30)
                                                 (* 0.5 (sqrt (* 2.0 (- im re))))
                                                 (* (sqrt (/ (* im im) re)) 0.5))))
                                            double code(double re, double im) {
                                            	double tmp;
                                            	if (re <= -0.00029) {
                                            		tmp = sqrt((-4.0 * re)) * 0.5;
                                            	} else if (re <= 1.5e-30) {
                                            		tmp = 0.5 * sqrt((2.0 * (im - re)));
                                            	} else {
                                            		tmp = sqrt(((im * im) / re)) * 0.5;
                                            	}
                                            	return tmp;
                                            }
                                            
                                            module fmin_fmax_functions
                                                implicit none
                                                private
                                                public fmax
                                                public fmin
                                            
                                                interface fmax
                                                    module procedure fmax88
                                                    module procedure fmax44
                                                    module procedure fmax84
                                                    module procedure fmax48
                                                end interface
                                                interface fmin
                                                    module procedure fmin88
                                                    module procedure fmin44
                                                    module procedure fmin84
                                                    module procedure fmin48
                                                end interface
                                            contains
                                                real(8) function fmax88(x, y) result (res)
                                                    real(8), intent (in) :: x
                                                    real(8), intent (in) :: y
                                                    res = merge(y, merge(x, max(x, y), y /= y), x /= x)
                                                end function
                                                real(4) function fmax44(x, y) result (res)
                                                    real(4), intent (in) :: x
                                                    real(4), intent (in) :: y
                                                    res = merge(y, merge(x, max(x, y), y /= y), x /= x)
                                                end function
                                                real(8) function fmax84(x, y) result(res)
                                                    real(8), intent (in) :: x
                                                    real(4), intent (in) :: y
                                                    res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
                                                end function
                                                real(8) function fmax48(x, y) result(res)
                                                    real(4), intent (in) :: x
                                                    real(8), intent (in) :: y
                                                    res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
                                                end function
                                                real(8) function fmin88(x, y) result (res)
                                                    real(8), intent (in) :: x
                                                    real(8), intent (in) :: y
                                                    res = merge(y, merge(x, min(x, y), y /= y), x /= x)
                                                end function
                                                real(4) function fmin44(x, y) result (res)
                                                    real(4), intent (in) :: x
                                                    real(4), intent (in) :: y
                                                    res = merge(y, merge(x, min(x, y), y /= y), x /= x)
                                                end function
                                                real(8) function fmin84(x, y) result(res)
                                                    real(8), intent (in) :: x
                                                    real(4), intent (in) :: y
                                                    res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
                                                end function
                                                real(8) function fmin48(x, y) result(res)
                                                    real(4), intent (in) :: x
                                                    real(8), intent (in) :: y
                                                    res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
                                                end function
                                            end module
                                            
                                            real(8) function code(re, im)
                                            use fmin_fmax_functions
                                                real(8), intent (in) :: re
                                                real(8), intent (in) :: im
                                                real(8) :: tmp
                                                if (re <= (-0.00029d0)) then
                                                    tmp = sqrt(((-4.0d0) * re)) * 0.5d0
                                                else if (re <= 1.5d-30) then
                                                    tmp = 0.5d0 * sqrt((2.0d0 * (im - re)))
                                                else
                                                    tmp = sqrt(((im * im) / re)) * 0.5d0
                                                end if
                                                code = tmp
                                            end function
                                            
                                            public static double code(double re, double im) {
                                            	double tmp;
                                            	if (re <= -0.00029) {
                                            		tmp = Math.sqrt((-4.0 * re)) * 0.5;
                                            	} else if (re <= 1.5e-30) {
                                            		tmp = 0.5 * Math.sqrt((2.0 * (im - re)));
                                            	} else {
                                            		tmp = Math.sqrt(((im * im) / re)) * 0.5;
                                            	}
                                            	return tmp;
                                            }
                                            
                                            def code(re, im):
                                            	tmp = 0
                                            	if re <= -0.00029:
                                            		tmp = math.sqrt((-4.0 * re)) * 0.5
                                            	elif re <= 1.5e-30:
                                            		tmp = 0.5 * math.sqrt((2.0 * (im - re)))
                                            	else:
                                            		tmp = math.sqrt(((im * im) / re)) * 0.5
                                            	return tmp
                                            
                                            function code(re, im)
                                            	tmp = 0.0
                                            	if (re <= -0.00029)
                                            		tmp = Float64(sqrt(Float64(-4.0 * re)) * 0.5);
                                            	elseif (re <= 1.5e-30)
                                            		tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(im - re))));
                                            	else
                                            		tmp = Float64(sqrt(Float64(Float64(im * im) / re)) * 0.5);
                                            	end
                                            	return tmp
                                            end
                                            
                                            function tmp_2 = code(re, im)
                                            	tmp = 0.0;
                                            	if (re <= -0.00029)
                                            		tmp = sqrt((-4.0 * re)) * 0.5;
                                            	elseif (re <= 1.5e-30)
                                            		tmp = 0.5 * sqrt((2.0 * (im - re)));
                                            	else
                                            		tmp = sqrt(((im * im) / re)) * 0.5;
                                            	end
                                            	tmp_2 = tmp;
                                            end
                                            
                                            code[re_, im_] := If[LessEqual[re, -0.00029], N[(N[Sqrt[N[(-4.0 * re), $MachinePrecision]], $MachinePrecision] * 0.5), $MachinePrecision], If[LessEqual[re, 1.5e-30], N[(0.5 * N[Sqrt[N[(2.0 * N[(im - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(N[Sqrt[N[(N[(im * im), $MachinePrecision] / re), $MachinePrecision]], $MachinePrecision] * 0.5), $MachinePrecision]]]
                                            
                                            \begin{array}{l}
                                            
                                            \\
                                            \begin{array}{l}
                                            \mathbf{if}\;re \leq -0.00029:\\
                                            \;\;\;\;\sqrt{-4 \cdot re} \cdot 0.5\\
                                            
                                            \mathbf{elif}\;re \leq 1.5 \cdot 10^{-30}:\\
                                            \;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(im - re\right)}\\
                                            
                                            \mathbf{else}:\\
                                            \;\;\;\;\sqrt{\frac{im \cdot im}{re}} \cdot 0.5\\
                                            
                                            
                                            \end{array}
                                            \end{array}
                                            
                                            Derivation
                                            1. Split input into 3 regimes
                                            2. if re < -2.9e-4

                                              1. Initial program 50.4%

                                                \[0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)} \]
                                              2. Add Preprocessing
                                              3. Step-by-step derivation
                                                1. lift-*.f64N/A

                                                  \[\leadsto \color{blue}{\frac{1}{2} \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)}} \]
                                                2. *-commutativeN/A

                                                  \[\leadsto \color{blue}{\sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)} \cdot \frac{1}{2}} \]
                                                3. lower-*.f6450.4

                                                  \[\leadsto \color{blue}{\sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)} \cdot 0.5} \]
                                                4. lift-*.f64N/A

                                                  \[\leadsto \sqrt{\color{blue}{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)}} \cdot \frac{1}{2} \]
                                                5. *-commutativeN/A

                                                  \[\leadsto \sqrt{\color{blue}{\left(\sqrt{re \cdot re + im \cdot im} - re\right) \cdot 2}} \cdot \frac{1}{2} \]
                                                6. lower-*.f6450.4

                                                  \[\leadsto \sqrt{\color{blue}{\left(\sqrt{re \cdot re + im \cdot im} - re\right) \cdot 2}} \cdot 0.5 \]
                                                7. lift-sqrt.f64N/A

                                                  \[\leadsto \sqrt{\left(\color{blue}{\sqrt{re \cdot re + im \cdot im}} - re\right) \cdot 2} \cdot \frac{1}{2} \]
                                                8. lift-+.f64N/A

                                                  \[\leadsto \sqrt{\left(\sqrt{\color{blue}{re \cdot re + im \cdot im}} - re\right) \cdot 2} \cdot \frac{1}{2} \]
                                                9. +-commutativeN/A

                                                  \[\leadsto \sqrt{\left(\sqrt{\color{blue}{im \cdot im + re \cdot re}} - re\right) \cdot 2} \cdot \frac{1}{2} \]
                                                10. lift-*.f64N/A

                                                  \[\leadsto \sqrt{\left(\sqrt{\color{blue}{im \cdot im} + re \cdot re} - re\right) \cdot 2} \cdot \frac{1}{2} \]
                                                11. lift-*.f64N/A

                                                  \[\leadsto \sqrt{\left(\sqrt{im \cdot im + \color{blue}{re \cdot re}} - re\right) \cdot 2} \cdot \frac{1}{2} \]
                                                12. lower-hypot.f64100.0

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

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

                                                \[\leadsto \sqrt{\color{blue}{-4 \cdot re}} \cdot \frac{1}{2} \]
                                              6. Step-by-step derivation
                                                1. lower-*.f6477.7

                                                  \[\leadsto \sqrt{\color{blue}{-4 \cdot re}} \cdot 0.5 \]
                                              7. Applied rewrites77.7%

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

                                              if -2.9e-4 < re < 1.49999999999999995e-30

                                              1. Initial program 57.4%

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

                                                \[\leadsto \frac{1}{2} \cdot \sqrt{2 \cdot \color{blue}{\left(im + -1 \cdot re\right)}} \]
                                              4. Step-by-step derivation
                                                1. fp-cancel-sign-sub-invN/A

                                                  \[\leadsto \frac{1}{2} \cdot \sqrt{2 \cdot \color{blue}{\left(im - \left(\mathsf{neg}\left(-1\right)\right) \cdot re\right)}} \]
                                                2. metadata-evalN/A

                                                  \[\leadsto \frac{1}{2} \cdot \sqrt{2 \cdot \left(im - \color{blue}{1} \cdot re\right)} \]
                                                3. *-lft-identityN/A

                                                  \[\leadsto \frac{1}{2} \cdot \sqrt{2 \cdot \left(im - \color{blue}{re}\right)} \]
                                                4. lower--.f6481.1

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

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

                                              if 1.49999999999999995e-30 < re

                                              1. Initial program 10.5%

                                                \[0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)} \]
                                              2. Add Preprocessing
                                              3. Step-by-step derivation
                                                1. lift-*.f64N/A

                                                  \[\leadsto \color{blue}{\frac{1}{2} \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)}} \]
                                                2. *-commutativeN/A

                                                  \[\leadsto \color{blue}{\sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)} \cdot \frac{1}{2}} \]
                                                3. lower-*.f6410.5

                                                  \[\leadsto \color{blue}{\sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)} \cdot 0.5} \]
                                                4. lift-*.f64N/A

                                                  \[\leadsto \sqrt{\color{blue}{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)}} \cdot \frac{1}{2} \]
                                                5. *-commutativeN/A

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

                                                  \[\leadsto \sqrt{\color{blue}{\left(\sqrt{re \cdot re + im \cdot im} - re\right) \cdot 2}} \cdot 0.5 \]
                                                7. lift-sqrt.f64N/A

                                                  \[\leadsto \sqrt{\left(\color{blue}{\sqrt{re \cdot re + im \cdot im}} - re\right) \cdot 2} \cdot \frac{1}{2} \]
                                                8. lift-+.f64N/A

                                                  \[\leadsto \sqrt{\left(\sqrt{\color{blue}{re \cdot re + im \cdot im}} - re\right) \cdot 2} \cdot \frac{1}{2} \]
                                                9. +-commutativeN/A

                                                  \[\leadsto \sqrt{\left(\sqrt{\color{blue}{im \cdot im + re \cdot re}} - re\right) \cdot 2} \cdot \frac{1}{2} \]
                                                10. lift-*.f64N/A

                                                  \[\leadsto \sqrt{\left(\sqrt{\color{blue}{im \cdot im} + re \cdot re} - re\right) \cdot 2} \cdot \frac{1}{2} \]
                                                11. lift-*.f64N/A

                                                  \[\leadsto \sqrt{\left(\sqrt{im \cdot im + \color{blue}{re \cdot re}} - re\right) \cdot 2} \cdot \frac{1}{2} \]
                                                12. lower-hypot.f6438.4

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

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

                                                \[\leadsto \sqrt{\color{blue}{\frac{{im}^{2}}{re}}} \cdot \frac{1}{2} \]
                                              6. Step-by-step derivation
                                                1. lower-/.f64N/A

                                                  \[\leadsto \sqrt{\color{blue}{\frac{{im}^{2}}{re}}} \cdot \frac{1}{2} \]
                                                2. unpow2N/A

                                                  \[\leadsto \sqrt{\frac{\color{blue}{im \cdot im}}{re}} \cdot \frac{1}{2} \]
                                                3. lower-*.f6452.7

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

                                                \[\leadsto \sqrt{\color{blue}{\frac{im \cdot im}{re}}} \cdot 0.5 \]
                                            3. Recombined 3 regimes into one program.
                                            4. Add Preprocessing

                                            Alternative 12: 64.6% accurate, 1.7× speedup?

                                            \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;re \leq -0.00024:\\ \;\;\;\;\sqrt{-4 \cdot re} \cdot 0.5\\ \mathbf{else}:\\ \;\;\;\;\sqrt{im + im} \cdot 0.5\\ \end{array} \end{array} \]
                                            (FPCore (re im)
                                             :precision binary64
                                             (if (<= re -0.00024) (* (sqrt (* -4.0 re)) 0.5) (* (sqrt (+ im im)) 0.5)))
                                            double code(double re, double im) {
                                            	double tmp;
                                            	if (re <= -0.00024) {
                                            		tmp = sqrt((-4.0 * re)) * 0.5;
                                            	} else {
                                            		tmp = sqrt((im + im)) * 0.5;
                                            	}
                                            	return tmp;
                                            }
                                            
                                            module fmin_fmax_functions
                                                implicit none
                                                private
                                                public fmax
                                                public fmin
                                            
                                                interface fmax
                                                    module procedure fmax88
                                                    module procedure fmax44
                                                    module procedure fmax84
                                                    module procedure fmax48
                                                end interface
                                                interface fmin
                                                    module procedure fmin88
                                                    module procedure fmin44
                                                    module procedure fmin84
                                                    module procedure fmin48
                                                end interface
                                            contains
                                                real(8) function fmax88(x, y) result (res)
                                                    real(8), intent (in) :: x
                                                    real(8), intent (in) :: y
                                                    res = merge(y, merge(x, max(x, y), y /= y), x /= x)
                                                end function
                                                real(4) function fmax44(x, y) result (res)
                                                    real(4), intent (in) :: x
                                                    real(4), intent (in) :: y
                                                    res = merge(y, merge(x, max(x, y), y /= y), x /= x)
                                                end function
                                                real(8) function fmax84(x, y) result(res)
                                                    real(8), intent (in) :: x
                                                    real(4), intent (in) :: y
                                                    res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
                                                end function
                                                real(8) function fmax48(x, y) result(res)
                                                    real(4), intent (in) :: x
                                                    real(8), intent (in) :: y
                                                    res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
                                                end function
                                                real(8) function fmin88(x, y) result (res)
                                                    real(8), intent (in) :: x
                                                    real(8), intent (in) :: y
                                                    res = merge(y, merge(x, min(x, y), y /= y), x /= x)
                                                end function
                                                real(4) function fmin44(x, y) result (res)
                                                    real(4), intent (in) :: x
                                                    real(4), intent (in) :: y
                                                    res = merge(y, merge(x, min(x, y), y /= y), x /= x)
                                                end function
                                                real(8) function fmin84(x, y) result(res)
                                                    real(8), intent (in) :: x
                                                    real(4), intent (in) :: y
                                                    res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
                                                end function
                                                real(8) function fmin48(x, y) result(res)
                                                    real(4), intent (in) :: x
                                                    real(8), intent (in) :: y
                                                    res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
                                                end function
                                            end module
                                            
                                            real(8) function code(re, im)
                                            use fmin_fmax_functions
                                                real(8), intent (in) :: re
                                                real(8), intent (in) :: im
                                                real(8) :: tmp
                                                if (re <= (-0.00024d0)) then
                                                    tmp = sqrt(((-4.0d0) * re)) * 0.5d0
                                                else
                                                    tmp = sqrt((im + im)) * 0.5d0
                                                end if
                                                code = tmp
                                            end function
                                            
                                            public static double code(double re, double im) {
                                            	double tmp;
                                            	if (re <= -0.00024) {
                                            		tmp = Math.sqrt((-4.0 * re)) * 0.5;
                                            	} else {
                                            		tmp = Math.sqrt((im + im)) * 0.5;
                                            	}
                                            	return tmp;
                                            }
                                            
                                            def code(re, im):
                                            	tmp = 0
                                            	if re <= -0.00024:
                                            		tmp = math.sqrt((-4.0 * re)) * 0.5
                                            	else:
                                            		tmp = math.sqrt((im + im)) * 0.5
                                            	return tmp
                                            
                                            function code(re, im)
                                            	tmp = 0.0
                                            	if (re <= -0.00024)
                                            		tmp = Float64(sqrt(Float64(-4.0 * re)) * 0.5);
                                            	else
                                            		tmp = Float64(sqrt(Float64(im + im)) * 0.5);
                                            	end
                                            	return tmp
                                            end
                                            
                                            function tmp_2 = code(re, im)
                                            	tmp = 0.0;
                                            	if (re <= -0.00024)
                                            		tmp = sqrt((-4.0 * re)) * 0.5;
                                            	else
                                            		tmp = sqrt((im + im)) * 0.5;
                                            	end
                                            	tmp_2 = tmp;
                                            end
                                            
                                            code[re_, im_] := If[LessEqual[re, -0.00024], N[(N[Sqrt[N[(-4.0 * re), $MachinePrecision]], $MachinePrecision] * 0.5), $MachinePrecision], N[(N[Sqrt[N[(im + im), $MachinePrecision]], $MachinePrecision] * 0.5), $MachinePrecision]]
                                            
                                            \begin{array}{l}
                                            
                                            \\
                                            \begin{array}{l}
                                            \mathbf{if}\;re \leq -0.00024:\\
                                            \;\;\;\;\sqrt{-4 \cdot re} \cdot 0.5\\
                                            
                                            \mathbf{else}:\\
                                            \;\;\;\;\sqrt{im + im} \cdot 0.5\\
                                            
                                            
                                            \end{array}
                                            \end{array}
                                            
                                            Derivation
                                            1. Split input into 2 regimes
                                            2. if re < -2.40000000000000006e-4

                                              1. Initial program 50.4%

                                                \[0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)} \]
                                              2. Add Preprocessing
                                              3. Step-by-step derivation
                                                1. lift-*.f64N/A

                                                  \[\leadsto \color{blue}{\frac{1}{2} \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)}} \]
                                                2. *-commutativeN/A

                                                  \[\leadsto \color{blue}{\sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)} \cdot \frac{1}{2}} \]
                                                3. lower-*.f6450.4

                                                  \[\leadsto \color{blue}{\sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)} \cdot 0.5} \]
                                                4. lift-*.f64N/A

                                                  \[\leadsto \sqrt{\color{blue}{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)}} \cdot \frac{1}{2} \]
                                                5. *-commutativeN/A

                                                  \[\leadsto \sqrt{\color{blue}{\left(\sqrt{re \cdot re + im \cdot im} - re\right) \cdot 2}} \cdot \frac{1}{2} \]
                                                6. lower-*.f6450.4

                                                  \[\leadsto \sqrt{\color{blue}{\left(\sqrt{re \cdot re + im \cdot im} - re\right) \cdot 2}} \cdot 0.5 \]
                                                7. lift-sqrt.f64N/A

                                                  \[\leadsto \sqrt{\left(\color{blue}{\sqrt{re \cdot re + im \cdot im}} - re\right) \cdot 2} \cdot \frac{1}{2} \]
                                                8. lift-+.f64N/A

                                                  \[\leadsto \sqrt{\left(\sqrt{\color{blue}{re \cdot re + im \cdot im}} - re\right) \cdot 2} \cdot \frac{1}{2} \]
                                                9. +-commutativeN/A

                                                  \[\leadsto \sqrt{\left(\sqrt{\color{blue}{im \cdot im + re \cdot re}} - re\right) \cdot 2} \cdot \frac{1}{2} \]
                                                10. lift-*.f64N/A

                                                  \[\leadsto \sqrt{\left(\sqrt{\color{blue}{im \cdot im} + re \cdot re} - re\right) \cdot 2} \cdot \frac{1}{2} \]
                                                11. lift-*.f64N/A

                                                  \[\leadsto \sqrt{\left(\sqrt{im \cdot im + \color{blue}{re \cdot re}} - re\right) \cdot 2} \cdot \frac{1}{2} \]
                                                12. lower-hypot.f64100.0

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

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

                                                \[\leadsto \sqrt{\color{blue}{-4 \cdot re}} \cdot \frac{1}{2} \]
                                              6. Step-by-step derivation
                                                1. lower-*.f6477.7

                                                  \[\leadsto \sqrt{\color{blue}{-4 \cdot re}} \cdot 0.5 \]
                                              7. Applied rewrites77.7%

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

                                              if -2.40000000000000006e-4 < re

                                              1. Initial program 39.8%

                                                \[0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)} \]
                                              2. Add Preprocessing
                                              3. Step-by-step derivation
                                                1. lift-*.f64N/A

                                                  \[\leadsto \color{blue}{\frac{1}{2} \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)}} \]
                                                2. *-commutativeN/A

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

                                                  \[\leadsto \color{blue}{\sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)} \cdot 0.5} \]
                                                4. lift-*.f64N/A

                                                  \[\leadsto \sqrt{\color{blue}{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)}} \cdot \frac{1}{2} \]
                                                5. *-commutativeN/A

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

                                                  \[\leadsto \sqrt{\color{blue}{\left(\sqrt{re \cdot re + im \cdot im} - re\right) \cdot 2}} \cdot 0.5 \]
                                                7. lift-sqrt.f64N/A

                                                  \[\leadsto \sqrt{\left(\color{blue}{\sqrt{re \cdot re + im \cdot im}} - re\right) \cdot 2} \cdot \frac{1}{2} \]
                                                8. lift-+.f64N/A

                                                  \[\leadsto \sqrt{\left(\sqrt{\color{blue}{re \cdot re + im \cdot im}} - re\right) \cdot 2} \cdot \frac{1}{2} \]
                                                9. +-commutativeN/A

                                                  \[\leadsto \sqrt{\left(\sqrt{\color{blue}{im \cdot im + re \cdot re}} - re\right) \cdot 2} \cdot \frac{1}{2} \]
                                                10. lift-*.f64N/A

                                                  \[\leadsto \sqrt{\left(\sqrt{\color{blue}{im \cdot im} + re \cdot re} - re\right) \cdot 2} \cdot \frac{1}{2} \]
                                                11. lift-*.f64N/A

                                                  \[\leadsto \sqrt{\left(\sqrt{im \cdot im + \color{blue}{re \cdot re}} - re\right) \cdot 2} \cdot \frac{1}{2} \]
                                                12. lower-hypot.f6472.6

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

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

                                                \[\leadsto \sqrt{\color{blue}{2 \cdot im}} \cdot \frac{1}{2} \]
                                              6. Step-by-step derivation
                                                1. lower-*.f6460.5

                                                  \[\leadsto \sqrt{\color{blue}{2 \cdot im}} \cdot 0.5 \]
                                              7. Applied rewrites60.5%

                                                \[\leadsto \sqrt{\color{blue}{2 \cdot im}} \cdot 0.5 \]
                                              8. Step-by-step derivation
                                                1. Applied rewrites60.5%

                                                  \[\leadsto \sqrt{im + \color{blue}{im}} \cdot 0.5 \]
                                              9. Recombined 2 regimes into one program.
                                              10. Add Preprocessing

                                              Alternative 13: 51.8% accurate, 2.5× speedup?

                                              \[\begin{array}{l} \\ \sqrt{im + im} \cdot 0.5 \end{array} \]
                                              (FPCore (re im) :precision binary64 (* (sqrt (+ im im)) 0.5))
                                              double code(double re, double im) {
                                              	return sqrt((im + im)) * 0.5;
                                              }
                                              
                                              module fmin_fmax_functions
                                                  implicit none
                                                  private
                                                  public fmax
                                                  public fmin
                                              
                                                  interface fmax
                                                      module procedure fmax88
                                                      module procedure fmax44
                                                      module procedure fmax84
                                                      module procedure fmax48
                                                  end interface
                                                  interface fmin
                                                      module procedure fmin88
                                                      module procedure fmin44
                                                      module procedure fmin84
                                                      module procedure fmin48
                                                  end interface
                                              contains
                                                  real(8) function fmax88(x, y) result (res)
                                                      real(8), intent (in) :: x
                                                      real(8), intent (in) :: y
                                                      res = merge(y, merge(x, max(x, y), y /= y), x /= x)
                                                  end function
                                                  real(4) function fmax44(x, y) result (res)
                                                      real(4), intent (in) :: x
                                                      real(4), intent (in) :: y
                                                      res = merge(y, merge(x, max(x, y), y /= y), x /= x)
                                                  end function
                                                  real(8) function fmax84(x, y) result(res)
                                                      real(8), intent (in) :: x
                                                      real(4), intent (in) :: y
                                                      res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
                                                  end function
                                                  real(8) function fmax48(x, y) result(res)
                                                      real(4), intent (in) :: x
                                                      real(8), intent (in) :: y
                                                      res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
                                                  end function
                                                  real(8) function fmin88(x, y) result (res)
                                                      real(8), intent (in) :: x
                                                      real(8), intent (in) :: y
                                                      res = merge(y, merge(x, min(x, y), y /= y), x /= x)
                                                  end function
                                                  real(4) function fmin44(x, y) result (res)
                                                      real(4), intent (in) :: x
                                                      real(4), intent (in) :: y
                                                      res = merge(y, merge(x, min(x, y), y /= y), x /= x)
                                                  end function
                                                  real(8) function fmin84(x, y) result(res)
                                                      real(8), intent (in) :: x
                                                      real(4), intent (in) :: y
                                                      res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
                                                  end function
                                                  real(8) function fmin48(x, y) result(res)
                                                      real(4), intent (in) :: x
                                                      real(8), intent (in) :: y
                                                      res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
                                                  end function
                                              end module
                                              
                                              real(8) function code(re, im)
                                              use fmin_fmax_functions
                                                  real(8), intent (in) :: re
                                                  real(8), intent (in) :: im
                                                  code = sqrt((im + im)) * 0.5d0
                                              end function
                                              
                                              public static double code(double re, double im) {
                                              	return Math.sqrt((im + im)) * 0.5;
                                              }
                                              
                                              def code(re, im):
                                              	return math.sqrt((im + im)) * 0.5
                                              
                                              function code(re, im)
                                              	return Float64(sqrt(Float64(im + im)) * 0.5)
                                              end
                                              
                                              function tmp = code(re, im)
                                              	tmp = sqrt((im + im)) * 0.5;
                                              end
                                              
                                              code[re_, im_] := N[(N[Sqrt[N[(im + im), $MachinePrecision]], $MachinePrecision] * 0.5), $MachinePrecision]
                                              
                                              \begin{array}{l}
                                              
                                              \\
                                              \sqrt{im + im} \cdot 0.5
                                              \end{array}
                                              
                                              Derivation
                                              1. Initial program 42.1%

                                                \[0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)} \]
                                              2. Add Preprocessing
                                              3. Step-by-step derivation
                                                1. lift-*.f64N/A

                                                  \[\leadsto \color{blue}{\frac{1}{2} \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)}} \]
                                                2. *-commutativeN/A

                                                  \[\leadsto \color{blue}{\sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)} \cdot \frac{1}{2}} \]
                                                3. lower-*.f6442.1

                                                  \[\leadsto \color{blue}{\sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)} \cdot 0.5} \]
                                                4. lift-*.f64N/A

                                                  \[\leadsto \sqrt{\color{blue}{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)}} \cdot \frac{1}{2} \]
                                                5. *-commutativeN/A

                                                  \[\leadsto \sqrt{\color{blue}{\left(\sqrt{re \cdot re + im \cdot im} - re\right) \cdot 2}} \cdot \frac{1}{2} \]
                                                6. lower-*.f6442.1

                                                  \[\leadsto \sqrt{\color{blue}{\left(\sqrt{re \cdot re + im \cdot im} - re\right) \cdot 2}} \cdot 0.5 \]
                                                7. lift-sqrt.f64N/A

                                                  \[\leadsto \sqrt{\left(\color{blue}{\sqrt{re \cdot re + im \cdot im}} - re\right) \cdot 2} \cdot \frac{1}{2} \]
                                                8. lift-+.f64N/A

                                                  \[\leadsto \sqrt{\left(\sqrt{\color{blue}{re \cdot re + im \cdot im}} - re\right) \cdot 2} \cdot \frac{1}{2} \]
                                                9. +-commutativeN/A

                                                  \[\leadsto \sqrt{\left(\sqrt{\color{blue}{im \cdot im + re \cdot re}} - re\right) \cdot 2} \cdot \frac{1}{2} \]
                                                10. lift-*.f64N/A

                                                  \[\leadsto \sqrt{\left(\sqrt{\color{blue}{im \cdot im} + re \cdot re} - re\right) \cdot 2} \cdot \frac{1}{2} \]
                                                11. lift-*.f64N/A

                                                  \[\leadsto \sqrt{\left(\sqrt{im \cdot im + \color{blue}{re \cdot re}} - re\right) \cdot 2} \cdot \frac{1}{2} \]
                                                12. lower-hypot.f6478.6

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

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

                                                \[\leadsto \sqrt{\color{blue}{2 \cdot im}} \cdot \frac{1}{2} \]
                                              6. Step-by-step derivation
                                                1. lower-*.f6452.9

                                                  \[\leadsto \sqrt{\color{blue}{2 \cdot im}} \cdot 0.5 \]
                                              7. Applied rewrites52.9%

                                                \[\leadsto \sqrt{\color{blue}{2 \cdot im}} \cdot 0.5 \]
                                              8. Step-by-step derivation
                                                1. Applied rewrites52.9%

                                                  \[\leadsto \sqrt{im + \color{blue}{im}} \cdot 0.5 \]
                                                2. Add Preprocessing

                                                Reproduce

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