math.sqrt on complex, real part

Percentage Accurate: 41.9% → 73.2%
Time: 7.7s
Alternatives: 6
Speedup: 1.9×

Specification

?
\[\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 6 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.9% 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: 73.2% accurate, 0.6× speedup?

\[\begin{array}{l} im_m = \left|im\right| \\ \begin{array}{l} \mathbf{if}\;re \leq -3.6 \cdot 10^{+22}:\\ \;\;\;\;0.5 \cdot \sqrt{\left(-im\_m\right) \cdot \frac{im\_m}{re}}\\ \mathbf{elif}\;re \leq 1.9 \cdot 10^{-18}:\\ \;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(\frac{1}{\frac{1 - \mathsf{ratio\_of\_squares}\left(re, im\_m\right) \cdot 0.5}{im\_m}} + re\right)}\\ \mathbf{elif}\;re \leq 2 \cdot 10^{+123}:\\ \;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im\_m \cdot im\_m} + re\right)}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{re}\\ \end{array} \end{array} \]
im_m = (fabs.f64 im)
(FPCore (re im_m)
 :precision binary64
 (if (<= re -3.6e+22)
   (* 0.5 (sqrt (* (- im_m) (/ im_m re))))
   (if (<= re 1.9e-18)
     (*
      0.5
      (sqrt
       (*
        2.0
        (+ (/ 1.0 (/ (- 1.0 (* (ratio-of-squares re im_m) 0.5)) im_m)) re))))
     (if (<= re 2e+123)
       (* 0.5 (sqrt (* 2.0 (+ (sqrt (+ (* re re) (* im_m im_m))) re))))
       (sqrt re)))))
\begin{array}{l}
im_m = \left|im\right|

\\
\begin{array}{l}
\mathbf{if}\;re \leq -3.6 \cdot 10^{+22}:\\
\;\;\;\;0.5 \cdot \sqrt{\left(-im\_m\right) \cdot \frac{im\_m}{re}}\\

\mathbf{elif}\;re \leq 1.9 \cdot 10^{-18}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(\frac{1}{\frac{1 - \mathsf{ratio\_of\_squares}\left(re, im\_m\right) \cdot 0.5}{im\_m}} + re\right)}\\

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

\mathbf{else}:\\
\;\;\;\;\sqrt{re}\\


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if re < -3.6e22

    1. Initial program 7.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 -inf

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

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

        \[\leadsto \frac{1}{2} \cdot \sqrt{-\frac{{im}^{2}}{re}} \]
      3. lower-/.f64N/A

        \[\leadsto \frac{1}{2} \cdot \sqrt{-\frac{{im}^{2}}{re}} \]
      4. pow2N/A

        \[\leadsto \frac{1}{2} \cdot \sqrt{-\frac{im \cdot im}{re}} \]
      5. lift-*.f6446.1

        \[\leadsto 0.5 \cdot \sqrt{-\frac{im \cdot im}{re}} \]
    5. Applied rewrites46.1%

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

        \[\leadsto \frac{1}{2} \cdot \sqrt{-\frac{im \cdot im}{re}} \]
      2. lift-/.f64N/A

        \[\leadsto \frac{1}{2} \cdot \sqrt{-\frac{im \cdot im}{re}} \]
      3. associate-/l*N/A

        \[\leadsto \frac{1}{2} \cdot \sqrt{-im \cdot \frac{im}{re}} \]
      4. lower-*.f64N/A

        \[\leadsto \frac{1}{2} \cdot \sqrt{-im \cdot \frac{im}{re}} \]
      5. lower-/.f6447.9

        \[\leadsto 0.5 \cdot \sqrt{-im \cdot \frac{im}{re}} \]
    7. Applied rewrites47.9%

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

    if -3.6e22 < re < 1.8999999999999999e-18

    1. Initial program 58.0%

      \[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-sqrt.f64N/A

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

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

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

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

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

        \[\leadsto \frac{1}{2} \cdot \sqrt{2 \cdot \left({\left(re \cdot re + im \cdot im\right)}^{\color{blue}{\left(\mathsf{neg}\left(\frac{-1}{2}\right)\right)}} + re\right)} \]
      7. pow-negN/A

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{1}{2} \cdot \sqrt{2 \cdot \left(\frac{1}{{\left(im \cdot im + \color{blue}{re \cdot re}\right)}^{\frac{-1}{2}}} + re\right)} \]
      17. lift-*.f6457.9

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

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

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

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

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

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

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

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

        \[\leadsto \frac{1}{2} \cdot \sqrt{2 \cdot \left(\frac{1}{\frac{1 - \frac{{re}^{2}}{{im}^{2}} \cdot \frac{1}{2}}{im}} + re\right)} \]
      7. pow2N/A

        \[\leadsto \frac{1}{2} \cdot \sqrt{2 \cdot \left(\frac{1}{\frac{1 - \frac{re \cdot re}{{im}^{2}} \cdot \frac{1}{2}}{im}} + re\right)} \]
      8. pow2N/A

        \[\leadsto \frac{1}{2} \cdot \sqrt{2 \cdot \left(\frac{1}{\frac{1 - \frac{re \cdot re}{im \cdot im} \cdot \frac{1}{2}}{im}} + re\right)} \]
      9. lower-ratio-of-squares.f6447.1

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \left(\frac{1}{\frac{1 - \mathsf{ratio\_of\_squares}\left(re, im\right) \cdot 0.5}{im}} + re\right)} \]
    7. Applied rewrites47.1%

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

    if 1.8999999999999999e-18 < re < 1.99999999999999996e123

    1. Initial program 75.2%

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

    if 1.99999999999999996e123 < re

    1. Initial program 18.2%

      \[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}{im}} \]
    4. Step-by-step derivation
      1. Applied rewrites14.1%

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

          \[\leadsto \frac{1}{2} \cdot \sqrt{\color{blue}{2 \cdot im}} \]
        2. count-2-revN/A

          \[\leadsto \frac{1}{2} \cdot \sqrt{\color{blue}{im + im}} \]
        3. lower-+.f6414.1

          \[\leadsto 0.5 \cdot \sqrt{\color{blue}{im + im}} \]
      3. Applied rewrites14.1%

        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{im + im}} \]
      4. Taylor expanded in re around inf

        \[\leadsto \color{blue}{\sqrt{re}} \]
      5. Step-by-step derivation
        1. count-2-revN/A

          \[\leadsto \sqrt{re} \]
        2. lower-sqrt.f6486.7

          \[\leadsto \sqrt{re} \]
      6. Applied rewrites86.7%

        \[\leadsto \color{blue}{\sqrt{re}} \]
    5. Recombined 4 regimes into one program.
    6. Final simplification57.1%

      \[\leadsto \begin{array}{l} \mathbf{if}\;re \leq -3.6 \cdot 10^{+22}:\\ \;\;\;\;0.5 \cdot \sqrt{\left(-im\right) \cdot \frac{im}{re}}\\ \mathbf{elif}\;re \leq 1.9 \cdot 10^{-18}:\\ \;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(\frac{1}{\frac{1 - \mathsf{ratio\_of\_squares}\left(re, im\right) \cdot 0.5}{im}} + re\right)}\\ \mathbf{elif}\;re \leq 2 \cdot 10^{+123}:\\ \;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{re}\\ \end{array} \]
    7. Add Preprocessing

    Alternative 2: 73.1% accurate, 0.7× speedup?

    \[\begin{array}{l} im_m = \left|im\right| \\ \begin{array}{l} \mathbf{if}\;re \leq -3.6 \cdot 10^{+22}:\\ \;\;\;\;0.5 \cdot \sqrt{\left(-im\_m\right) \cdot \frac{im\_m}{re}}\\ \mathbf{elif}\;re \leq 1.9 \cdot 10^{-18}:\\ \;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(im\_m + re\right)}\\ \mathbf{elif}\;re \leq 2 \cdot 10^{+123}:\\ \;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im\_m \cdot im\_m} + re\right)}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{re}\\ \end{array} \end{array} \]
    im_m = (fabs.f64 im)
    (FPCore (re im_m)
     :precision binary64
     (if (<= re -3.6e+22)
       (* 0.5 (sqrt (* (- im_m) (/ im_m re))))
       (if (<= re 1.9e-18)
         (* 0.5 (sqrt (* 2.0 (+ im_m re))))
         (if (<= re 2e+123)
           (* 0.5 (sqrt (* 2.0 (+ (sqrt (+ (* re re) (* im_m im_m))) re))))
           (sqrt re)))))
    im_m = fabs(im);
    double code(double re, double im_m) {
    	double tmp;
    	if (re <= -3.6e+22) {
    		tmp = 0.5 * sqrt((-im_m * (im_m / re)));
    	} else if (re <= 1.9e-18) {
    		tmp = 0.5 * sqrt((2.0 * (im_m + re)));
    	} else if (re <= 2e+123) {
    		tmp = 0.5 * sqrt((2.0 * (sqrt(((re * re) + (im_m * im_m))) + re)));
    	} else {
    		tmp = sqrt(re);
    	}
    	return tmp;
    }
    
    im_m =     private
    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_m)
    use fmin_fmax_functions
        real(8), intent (in) :: re
        real(8), intent (in) :: im_m
        real(8) :: tmp
        if (re <= (-3.6d+22)) then
            tmp = 0.5d0 * sqrt((-im_m * (im_m / re)))
        else if (re <= 1.9d-18) then
            tmp = 0.5d0 * sqrt((2.0d0 * (im_m + re)))
        else if (re <= 2d+123) then
            tmp = 0.5d0 * sqrt((2.0d0 * (sqrt(((re * re) + (im_m * im_m))) + re)))
        else
            tmp = sqrt(re)
        end if
        code = tmp
    end function
    
    im_m = Math.abs(im);
    public static double code(double re, double im_m) {
    	double tmp;
    	if (re <= -3.6e+22) {
    		tmp = 0.5 * Math.sqrt((-im_m * (im_m / re)));
    	} else if (re <= 1.9e-18) {
    		tmp = 0.5 * Math.sqrt((2.0 * (im_m + re)));
    	} else if (re <= 2e+123) {
    		tmp = 0.5 * Math.sqrt((2.0 * (Math.sqrt(((re * re) + (im_m * im_m))) + re)));
    	} else {
    		tmp = Math.sqrt(re);
    	}
    	return tmp;
    }
    
    im_m = math.fabs(im)
    def code(re, im_m):
    	tmp = 0
    	if re <= -3.6e+22:
    		tmp = 0.5 * math.sqrt((-im_m * (im_m / re)))
    	elif re <= 1.9e-18:
    		tmp = 0.5 * math.sqrt((2.0 * (im_m + re)))
    	elif re <= 2e+123:
    		tmp = 0.5 * math.sqrt((2.0 * (math.sqrt(((re * re) + (im_m * im_m))) + re)))
    	else:
    		tmp = math.sqrt(re)
    	return tmp
    
    im_m = abs(im)
    function code(re, im_m)
    	tmp = 0.0
    	if (re <= -3.6e+22)
    		tmp = Float64(0.5 * sqrt(Float64(Float64(-im_m) * Float64(im_m / re))));
    	elseif (re <= 1.9e-18)
    		tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(im_m + re))));
    	elseif (re <= 2e+123)
    		tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(sqrt(Float64(Float64(re * re) + Float64(im_m * im_m))) + re))));
    	else
    		tmp = sqrt(re);
    	end
    	return tmp
    end
    
    im_m = abs(im);
    function tmp_2 = code(re, im_m)
    	tmp = 0.0;
    	if (re <= -3.6e+22)
    		tmp = 0.5 * sqrt((-im_m * (im_m / re)));
    	elseif (re <= 1.9e-18)
    		tmp = 0.5 * sqrt((2.0 * (im_m + re)));
    	elseif (re <= 2e+123)
    		tmp = 0.5 * sqrt((2.0 * (sqrt(((re * re) + (im_m * im_m))) + re)));
    	else
    		tmp = sqrt(re);
    	end
    	tmp_2 = tmp;
    end
    
    im_m = N[Abs[im], $MachinePrecision]
    code[re_, im$95$m_] := If[LessEqual[re, -3.6e+22], N[(0.5 * N[Sqrt[N[((-im$95$m) * N[(im$95$m / re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 1.9e-18], N[(0.5 * N[Sqrt[N[(2.0 * N[(im$95$m + re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 2e+123], N[(0.5 * N[Sqrt[N[(2.0 * N[(N[Sqrt[N[(N[(re * re), $MachinePrecision] + N[(im$95$m * im$95$m), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] + re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[Sqrt[re], $MachinePrecision]]]]
    
    \begin{array}{l}
    im_m = \left|im\right|
    
    \\
    \begin{array}{l}
    \mathbf{if}\;re \leq -3.6 \cdot 10^{+22}:\\
    \;\;\;\;0.5 \cdot \sqrt{\left(-im\_m\right) \cdot \frac{im\_m}{re}}\\
    
    \mathbf{elif}\;re \leq 1.9 \cdot 10^{-18}:\\
    \;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(im\_m + re\right)}\\
    
    \mathbf{elif}\;re \leq 2 \cdot 10^{+123}:\\
    \;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im\_m \cdot im\_m} + re\right)}\\
    
    \mathbf{else}:\\
    \;\;\;\;\sqrt{re}\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 4 regimes
    2. if re < -3.6e22

      1. Initial program 7.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 -inf

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

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

          \[\leadsto \frac{1}{2} \cdot \sqrt{-\frac{{im}^{2}}{re}} \]
        3. lower-/.f64N/A

          \[\leadsto \frac{1}{2} \cdot \sqrt{-\frac{{im}^{2}}{re}} \]
        4. pow2N/A

          \[\leadsto \frac{1}{2} \cdot \sqrt{-\frac{im \cdot im}{re}} \]
        5. lift-*.f6446.1

          \[\leadsto 0.5 \cdot \sqrt{-\frac{im \cdot im}{re}} \]
      5. Applied rewrites46.1%

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

          \[\leadsto \frac{1}{2} \cdot \sqrt{-\frac{im \cdot im}{re}} \]
        2. lift-/.f64N/A

          \[\leadsto \frac{1}{2} \cdot \sqrt{-\frac{im \cdot im}{re}} \]
        3. associate-/l*N/A

          \[\leadsto \frac{1}{2} \cdot \sqrt{-im \cdot \frac{im}{re}} \]
        4. lower-*.f64N/A

          \[\leadsto \frac{1}{2} \cdot \sqrt{-im \cdot \frac{im}{re}} \]
        5. lower-/.f6447.9

          \[\leadsto 0.5 \cdot \sqrt{-im \cdot \frac{im}{re}} \]
      7. Applied rewrites47.9%

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

      if -3.6e22 < re < 1.8999999999999999e-18

      1. Initial program 58.0%

        \[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 \left(\color{blue}{im} + re\right)} \]
      4. Step-by-step derivation
        1. Applied rewrites46.7%

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

        if 1.8999999999999999e-18 < re < 1.99999999999999996e123

        1. Initial program 75.2%

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

        if 1.99999999999999996e123 < re

        1. Initial program 18.2%

          \[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}{im}} \]
        4. Step-by-step derivation
          1. Applied rewrites14.1%

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

              \[\leadsto \frac{1}{2} \cdot \sqrt{\color{blue}{2 \cdot im}} \]
            2. count-2-revN/A

              \[\leadsto \frac{1}{2} \cdot \sqrt{\color{blue}{im + im}} \]
            3. lower-+.f6414.1

              \[\leadsto 0.5 \cdot \sqrt{\color{blue}{im + im}} \]
          3. Applied rewrites14.1%

            \[\leadsto 0.5 \cdot \sqrt{\color{blue}{im + im}} \]
          4. Taylor expanded in re around inf

            \[\leadsto \color{blue}{\sqrt{re}} \]
          5. Step-by-step derivation
            1. count-2-revN/A

              \[\leadsto \sqrt{re} \]
            2. lower-sqrt.f6486.7

              \[\leadsto \sqrt{re} \]
          6. Applied rewrites86.7%

            \[\leadsto \color{blue}{\sqrt{re}} \]
        5. Recombined 4 regimes into one program.
        6. Final simplification56.9%

          \[\leadsto \begin{array}{l} \mathbf{if}\;re \leq -3.6 \cdot 10^{+22}:\\ \;\;\;\;0.5 \cdot \sqrt{\left(-im\right) \cdot \frac{im}{re}}\\ \mathbf{elif}\;re \leq 1.9 \cdot 10^{-18}:\\ \;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(im + re\right)}\\ \mathbf{elif}\;re \leq 2 \cdot 10^{+123}:\\ \;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{re}\\ \end{array} \]
        7. Add Preprocessing

        Alternative 3: 71.5% accurate, 1.2× speedup?

        \[\begin{array}{l} im_m = \left|im\right| \\ \begin{array}{l} \mathbf{if}\;re \leq -3.6 \cdot 10^{+22}:\\ \;\;\;\;0.5 \cdot \sqrt{\left(-im\_m\right) \cdot \frac{im\_m}{re}}\\ \mathbf{elif}\;re \leq 8.2 \cdot 10^{-17}:\\ \;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(im\_m + re\right)}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{re}\\ \end{array} \end{array} \]
        im_m = (fabs.f64 im)
        (FPCore (re im_m)
         :precision binary64
         (if (<= re -3.6e+22)
           (* 0.5 (sqrt (* (- im_m) (/ im_m re))))
           (if (<= re 8.2e-17) (* 0.5 (sqrt (* 2.0 (+ im_m re)))) (sqrt re))))
        im_m = fabs(im);
        double code(double re, double im_m) {
        	double tmp;
        	if (re <= -3.6e+22) {
        		tmp = 0.5 * sqrt((-im_m * (im_m / re)));
        	} else if (re <= 8.2e-17) {
        		tmp = 0.5 * sqrt((2.0 * (im_m + re)));
        	} else {
        		tmp = sqrt(re);
        	}
        	return tmp;
        }
        
        im_m =     private
        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_m)
        use fmin_fmax_functions
            real(8), intent (in) :: re
            real(8), intent (in) :: im_m
            real(8) :: tmp
            if (re <= (-3.6d+22)) then
                tmp = 0.5d0 * sqrt((-im_m * (im_m / re)))
            else if (re <= 8.2d-17) then
                tmp = 0.5d0 * sqrt((2.0d0 * (im_m + re)))
            else
                tmp = sqrt(re)
            end if
            code = tmp
        end function
        
        im_m = Math.abs(im);
        public static double code(double re, double im_m) {
        	double tmp;
        	if (re <= -3.6e+22) {
        		tmp = 0.5 * Math.sqrt((-im_m * (im_m / re)));
        	} else if (re <= 8.2e-17) {
        		tmp = 0.5 * Math.sqrt((2.0 * (im_m + re)));
        	} else {
        		tmp = Math.sqrt(re);
        	}
        	return tmp;
        }
        
        im_m = math.fabs(im)
        def code(re, im_m):
        	tmp = 0
        	if re <= -3.6e+22:
        		tmp = 0.5 * math.sqrt((-im_m * (im_m / re)))
        	elif re <= 8.2e-17:
        		tmp = 0.5 * math.sqrt((2.0 * (im_m + re)))
        	else:
        		tmp = math.sqrt(re)
        	return tmp
        
        im_m = abs(im)
        function code(re, im_m)
        	tmp = 0.0
        	if (re <= -3.6e+22)
        		tmp = Float64(0.5 * sqrt(Float64(Float64(-im_m) * Float64(im_m / re))));
        	elseif (re <= 8.2e-17)
        		tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(im_m + re))));
        	else
        		tmp = sqrt(re);
        	end
        	return tmp
        end
        
        im_m = abs(im);
        function tmp_2 = code(re, im_m)
        	tmp = 0.0;
        	if (re <= -3.6e+22)
        		tmp = 0.5 * sqrt((-im_m * (im_m / re)));
        	elseif (re <= 8.2e-17)
        		tmp = 0.5 * sqrt((2.0 * (im_m + re)));
        	else
        		tmp = sqrt(re);
        	end
        	tmp_2 = tmp;
        end
        
        im_m = N[Abs[im], $MachinePrecision]
        code[re_, im$95$m_] := If[LessEqual[re, -3.6e+22], N[(0.5 * N[Sqrt[N[((-im$95$m) * N[(im$95$m / re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 8.2e-17], N[(0.5 * N[Sqrt[N[(2.0 * N[(im$95$m + re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[Sqrt[re], $MachinePrecision]]]
        
        \begin{array}{l}
        im_m = \left|im\right|
        
        \\
        \begin{array}{l}
        \mathbf{if}\;re \leq -3.6 \cdot 10^{+22}:\\
        \;\;\;\;0.5 \cdot \sqrt{\left(-im\_m\right) \cdot \frac{im\_m}{re}}\\
        
        \mathbf{elif}\;re \leq 8.2 \cdot 10^{-17}:\\
        \;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(im\_m + re\right)}\\
        
        \mathbf{else}:\\
        \;\;\;\;\sqrt{re}\\
        
        
        \end{array}
        \end{array}
        
        Derivation
        1. Split input into 3 regimes
        2. if re < -3.6e22

          1. Initial program 7.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 -inf

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

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

              \[\leadsto \frac{1}{2} \cdot \sqrt{-\frac{{im}^{2}}{re}} \]
            3. lower-/.f64N/A

              \[\leadsto \frac{1}{2} \cdot \sqrt{-\frac{{im}^{2}}{re}} \]
            4. pow2N/A

              \[\leadsto \frac{1}{2} \cdot \sqrt{-\frac{im \cdot im}{re}} \]
            5. lift-*.f6446.1

              \[\leadsto 0.5 \cdot \sqrt{-\frac{im \cdot im}{re}} \]
          5. Applied rewrites46.1%

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

              \[\leadsto \frac{1}{2} \cdot \sqrt{-\frac{im \cdot im}{re}} \]
            2. lift-/.f64N/A

              \[\leadsto \frac{1}{2} \cdot \sqrt{-\frac{im \cdot im}{re}} \]
            3. associate-/l*N/A

              \[\leadsto \frac{1}{2} \cdot \sqrt{-im \cdot \frac{im}{re}} \]
            4. lower-*.f64N/A

              \[\leadsto \frac{1}{2} \cdot \sqrt{-im \cdot \frac{im}{re}} \]
            5. lower-/.f6447.9

              \[\leadsto 0.5 \cdot \sqrt{-im \cdot \frac{im}{re}} \]
          7. Applied rewrites47.9%

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

          if -3.6e22 < re < 8.2000000000000001e-17

          1. Initial program 58.0%

            \[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 \left(\color{blue}{im} + re\right)} \]
          4. Step-by-step derivation
            1. Applied rewrites46.7%

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

            if 8.2000000000000001e-17 < re

            1. Initial program 42.8%

              \[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}{im}} \]
            4. Step-by-step derivation
              1. Applied rewrites15.5%

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

                  \[\leadsto \frac{1}{2} \cdot \sqrt{\color{blue}{2 \cdot im}} \]
                2. count-2-revN/A

                  \[\leadsto \frac{1}{2} \cdot \sqrt{\color{blue}{im + im}} \]
                3. lower-+.f6415.5

                  \[\leadsto 0.5 \cdot \sqrt{\color{blue}{im + im}} \]
              3. Applied rewrites15.5%

                \[\leadsto 0.5 \cdot \sqrt{\color{blue}{im + im}} \]
              4. Taylor expanded in re around inf

                \[\leadsto \color{blue}{\sqrt{re}} \]
              5. Step-by-step derivation
                1. count-2-revN/A

                  \[\leadsto \sqrt{re} \]
                2. lower-sqrt.f6475.8

                  \[\leadsto \sqrt{re} \]
              6. Applied rewrites75.8%

                \[\leadsto \color{blue}{\sqrt{re}} \]
            5. Recombined 3 regimes into one program.
            6. Final simplification55.2%

              \[\leadsto \begin{array}{l} \mathbf{if}\;re \leq -3.6 \cdot 10^{+22}:\\ \;\;\;\;0.5 \cdot \sqrt{\left(-im\right) \cdot \frac{im}{re}}\\ \mathbf{elif}\;re \leq 8.2 \cdot 10^{-17}:\\ \;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(im + re\right)}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{re}\\ \end{array} \]
            7. Add Preprocessing

            Alternative 4: 65.6% accurate, 1.5× speedup?

            \[\begin{array}{l} im_m = \left|im\right| \\ \begin{array}{l} \mathbf{if}\;re \leq -3.9 \cdot 10^{+211}:\\ \;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(\left(-re\right) + re\right)}\\ \mathbf{elif}\;re \leq 6.5 \cdot 10^{-17}:\\ \;\;\;\;0.5 \cdot \sqrt{im\_m + im\_m}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{re}\\ \end{array} \end{array} \]
            im_m = (fabs.f64 im)
            (FPCore (re im_m)
             :precision binary64
             (if (<= re -3.9e+211)
               (* 0.5 (sqrt (* 2.0 (+ (- re) re))))
               (if (<= re 6.5e-17) (* 0.5 (sqrt (+ im_m im_m))) (sqrt re))))
            im_m = fabs(im);
            double code(double re, double im_m) {
            	double tmp;
            	if (re <= -3.9e+211) {
            		tmp = 0.5 * sqrt((2.0 * (-re + re)));
            	} else if (re <= 6.5e-17) {
            		tmp = 0.5 * sqrt((im_m + im_m));
            	} else {
            		tmp = sqrt(re);
            	}
            	return tmp;
            }
            
            im_m =     private
            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_m)
            use fmin_fmax_functions
                real(8), intent (in) :: re
                real(8), intent (in) :: im_m
                real(8) :: tmp
                if (re <= (-3.9d+211)) then
                    tmp = 0.5d0 * sqrt((2.0d0 * (-re + re)))
                else if (re <= 6.5d-17) then
                    tmp = 0.5d0 * sqrt((im_m + im_m))
                else
                    tmp = sqrt(re)
                end if
                code = tmp
            end function
            
            im_m = Math.abs(im);
            public static double code(double re, double im_m) {
            	double tmp;
            	if (re <= -3.9e+211) {
            		tmp = 0.5 * Math.sqrt((2.0 * (-re + re)));
            	} else if (re <= 6.5e-17) {
            		tmp = 0.5 * Math.sqrt((im_m + im_m));
            	} else {
            		tmp = Math.sqrt(re);
            	}
            	return tmp;
            }
            
            im_m = math.fabs(im)
            def code(re, im_m):
            	tmp = 0
            	if re <= -3.9e+211:
            		tmp = 0.5 * math.sqrt((2.0 * (-re + re)))
            	elif re <= 6.5e-17:
            		tmp = 0.5 * math.sqrt((im_m + im_m))
            	else:
            		tmp = math.sqrt(re)
            	return tmp
            
            im_m = abs(im)
            function code(re, im_m)
            	tmp = 0.0
            	if (re <= -3.9e+211)
            		tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(Float64(-re) + re))));
            	elseif (re <= 6.5e-17)
            		tmp = Float64(0.5 * sqrt(Float64(im_m + im_m)));
            	else
            		tmp = sqrt(re);
            	end
            	return tmp
            end
            
            im_m = abs(im);
            function tmp_2 = code(re, im_m)
            	tmp = 0.0;
            	if (re <= -3.9e+211)
            		tmp = 0.5 * sqrt((2.0 * (-re + re)));
            	elseif (re <= 6.5e-17)
            		tmp = 0.5 * sqrt((im_m + im_m));
            	else
            		tmp = sqrt(re);
            	end
            	tmp_2 = tmp;
            end
            
            im_m = N[Abs[im], $MachinePrecision]
            code[re_, im$95$m_] := If[LessEqual[re, -3.9e+211], N[(0.5 * N[Sqrt[N[(2.0 * N[((-re) + re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 6.5e-17], N[(0.5 * N[Sqrt[N[(im$95$m + im$95$m), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[Sqrt[re], $MachinePrecision]]]
            
            \begin{array}{l}
            im_m = \left|im\right|
            
            \\
            \begin{array}{l}
            \mathbf{if}\;re \leq -3.9 \cdot 10^{+211}:\\
            \;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(\left(-re\right) + re\right)}\\
            
            \mathbf{elif}\;re \leq 6.5 \cdot 10^{-17}:\\
            \;\;\;\;0.5 \cdot \sqrt{im\_m + im\_m}\\
            
            \mathbf{else}:\\
            \;\;\;\;\sqrt{re}\\
            
            
            \end{array}
            \end{array}
            
            Derivation
            1. Split input into 3 regimes
            2. if re < -3.90000000000000023e211

              1. Initial program 2.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 -inf

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

                  \[\leadsto \frac{1}{2} \cdot \sqrt{2 \cdot \left(\left(\mathsf{neg}\left(re\right)\right) + re\right)} \]
                2. lower-neg.f6435.1

                  \[\leadsto 0.5 \cdot \sqrt{2 \cdot \left(\left(-re\right) + re\right)} \]
              5. Applied rewrites35.1%

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

              if -3.90000000000000023e211 < re < 6.4999999999999996e-17

              1. Initial program 45.1%

                \[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}{im}} \]
              4. Step-by-step derivation
                1. Applied rewrites38.6%

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

                    \[\leadsto \frac{1}{2} \cdot \sqrt{\color{blue}{2 \cdot im}} \]
                  2. count-2-revN/A

                    \[\leadsto \frac{1}{2} \cdot \sqrt{\color{blue}{im + im}} \]
                  3. lower-+.f6438.6

                    \[\leadsto 0.5 \cdot \sqrt{\color{blue}{im + im}} \]
                3. Applied rewrites38.6%

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

                if 6.4999999999999996e-17 < re

                1. Initial program 42.8%

                  \[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}{im}} \]
                4. Step-by-step derivation
                  1. Applied rewrites15.5%

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

                      \[\leadsto \frac{1}{2} \cdot \sqrt{\color{blue}{2 \cdot im}} \]
                    2. count-2-revN/A

                      \[\leadsto \frac{1}{2} \cdot \sqrt{\color{blue}{im + im}} \]
                    3. lower-+.f6415.5

                      \[\leadsto 0.5 \cdot \sqrt{\color{blue}{im + im}} \]
                  3. Applied rewrites15.5%

                    \[\leadsto 0.5 \cdot \sqrt{\color{blue}{im + im}} \]
                  4. Taylor expanded in re around inf

                    \[\leadsto \color{blue}{\sqrt{re}} \]
                  5. Step-by-step derivation
                    1. count-2-revN/A

                      \[\leadsto \sqrt{re} \]
                    2. lower-sqrt.f6475.8

                      \[\leadsto \sqrt{re} \]
                  6. Applied rewrites75.8%

                    \[\leadsto \color{blue}{\sqrt{re}} \]
                5. Recombined 3 regimes into one program.
                6. Add Preprocessing

                Alternative 5: 64.5% accurate, 1.9× speedup?

                \[\begin{array}{l} im_m = \left|im\right| \\ \begin{array}{l} \mathbf{if}\;re \leq 6.5 \cdot 10^{-17}:\\ \;\;\;\;0.5 \cdot \sqrt{im\_m + im\_m}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{re}\\ \end{array} \end{array} \]
                im_m = (fabs.f64 im)
                (FPCore (re im_m)
                 :precision binary64
                 (if (<= re 6.5e-17) (* 0.5 (sqrt (+ im_m im_m))) (sqrt re)))
                im_m = fabs(im);
                double code(double re, double im_m) {
                	double tmp;
                	if (re <= 6.5e-17) {
                		tmp = 0.5 * sqrt((im_m + im_m));
                	} else {
                		tmp = sqrt(re);
                	}
                	return tmp;
                }
                
                im_m =     private
                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_m)
                use fmin_fmax_functions
                    real(8), intent (in) :: re
                    real(8), intent (in) :: im_m
                    real(8) :: tmp
                    if (re <= 6.5d-17) then
                        tmp = 0.5d0 * sqrt((im_m + im_m))
                    else
                        tmp = sqrt(re)
                    end if
                    code = tmp
                end function
                
                im_m = Math.abs(im);
                public static double code(double re, double im_m) {
                	double tmp;
                	if (re <= 6.5e-17) {
                		tmp = 0.5 * Math.sqrt((im_m + im_m));
                	} else {
                		tmp = Math.sqrt(re);
                	}
                	return tmp;
                }
                
                im_m = math.fabs(im)
                def code(re, im_m):
                	tmp = 0
                	if re <= 6.5e-17:
                		tmp = 0.5 * math.sqrt((im_m + im_m))
                	else:
                		tmp = math.sqrt(re)
                	return tmp
                
                im_m = abs(im)
                function code(re, im_m)
                	tmp = 0.0
                	if (re <= 6.5e-17)
                		tmp = Float64(0.5 * sqrt(Float64(im_m + im_m)));
                	else
                		tmp = sqrt(re);
                	end
                	return tmp
                end
                
                im_m = abs(im);
                function tmp_2 = code(re, im_m)
                	tmp = 0.0;
                	if (re <= 6.5e-17)
                		tmp = 0.5 * sqrt((im_m + im_m));
                	else
                		tmp = sqrt(re);
                	end
                	tmp_2 = tmp;
                end
                
                im_m = N[Abs[im], $MachinePrecision]
                code[re_, im$95$m_] := If[LessEqual[re, 6.5e-17], N[(0.5 * N[Sqrt[N[(im$95$m + im$95$m), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[Sqrt[re], $MachinePrecision]]
                
                \begin{array}{l}
                im_m = \left|im\right|
                
                \\
                \begin{array}{l}
                \mathbf{if}\;re \leq 6.5 \cdot 10^{-17}:\\
                \;\;\;\;0.5 \cdot \sqrt{im\_m + im\_m}\\
                
                \mathbf{else}:\\
                \;\;\;\;\sqrt{re}\\
                
                
                \end{array}
                \end{array}
                
                Derivation
                1. Split input into 2 regimes
                2. if re < 6.4999999999999996e-17

                  1. Initial program 40.0%

                    \[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}{im}} \]
                  4. Step-by-step derivation
                    1. Applied rewrites34.1%

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

                        \[\leadsto \frac{1}{2} \cdot \sqrt{\color{blue}{2 \cdot im}} \]
                      2. count-2-revN/A

                        \[\leadsto \frac{1}{2} \cdot \sqrt{\color{blue}{im + im}} \]
                      3. lower-+.f6434.1

                        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{im + im}} \]
                    3. Applied rewrites34.1%

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

                    if 6.4999999999999996e-17 < re

                    1. Initial program 42.8%

                      \[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}{im}} \]
                    4. Step-by-step derivation
                      1. Applied rewrites15.5%

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

                          \[\leadsto \frac{1}{2} \cdot \sqrt{\color{blue}{2 \cdot im}} \]
                        2. count-2-revN/A

                          \[\leadsto \frac{1}{2} \cdot \sqrt{\color{blue}{im + im}} \]
                        3. lower-+.f6415.5

                          \[\leadsto 0.5 \cdot \sqrt{\color{blue}{im + im}} \]
                      3. Applied rewrites15.5%

                        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{im + im}} \]
                      4. Taylor expanded in re around inf

                        \[\leadsto \color{blue}{\sqrt{re}} \]
                      5. Step-by-step derivation
                        1. count-2-revN/A

                          \[\leadsto \sqrt{re} \]
                        2. lower-sqrt.f6475.8

                          \[\leadsto \sqrt{re} \]
                      6. Applied rewrites75.8%

                        \[\leadsto \color{blue}{\sqrt{re}} \]
                    5. Recombined 2 regimes into one program.
                    6. Add Preprocessing

                    Alternative 6: 26.6% accurate, 4.3× speedup?

                    \[\begin{array}{l} im_m = \left|im\right| \\ \sqrt{re} \end{array} \]
                    im_m = (fabs.f64 im)
                    (FPCore (re im_m) :precision binary64 (sqrt re))
                    im_m = fabs(im);
                    double code(double re, double im_m) {
                    	return sqrt(re);
                    }
                    
                    im_m =     private
                    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_m)
                    use fmin_fmax_functions
                        real(8), intent (in) :: re
                        real(8), intent (in) :: im_m
                        code = sqrt(re)
                    end function
                    
                    im_m = Math.abs(im);
                    public static double code(double re, double im_m) {
                    	return Math.sqrt(re);
                    }
                    
                    im_m = math.fabs(im)
                    def code(re, im_m):
                    	return math.sqrt(re)
                    
                    im_m = abs(im)
                    function code(re, im_m)
                    	return sqrt(re)
                    end
                    
                    im_m = abs(im);
                    function tmp = code(re, im_m)
                    	tmp = sqrt(re);
                    end
                    
                    im_m = N[Abs[im], $MachinePrecision]
                    code[re_, im$95$m_] := N[Sqrt[re], $MachinePrecision]
                    
                    \begin{array}{l}
                    im_m = \left|im\right|
                    
                    \\
                    \sqrt{re}
                    \end{array}
                    
                    Derivation
                    1. Initial program 40.8%

                      \[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}{im}} \]
                    4. Step-by-step derivation
                      1. Applied rewrites28.9%

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

                          \[\leadsto \frac{1}{2} \cdot \sqrt{\color{blue}{2 \cdot im}} \]
                        2. count-2-revN/A

                          \[\leadsto \frac{1}{2} \cdot \sqrt{\color{blue}{im + im}} \]
                        3. lower-+.f6428.9

                          \[\leadsto 0.5 \cdot \sqrt{\color{blue}{im + im}} \]
                      3. Applied rewrites28.9%

                        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{im + im}} \]
                      4. Taylor expanded in re around inf

                        \[\leadsto \color{blue}{\sqrt{re}} \]
                      5. Step-by-step derivation
                        1. count-2-revN/A

                          \[\leadsto \sqrt{re} \]
                        2. lower-sqrt.f6427.0

                          \[\leadsto \sqrt{re} \]
                      6. Applied rewrites27.0%

                        \[\leadsto \color{blue}{\sqrt{re}} \]
                      7. Add Preprocessing

                      Reproduce

                      ?
                      herbie shell --seed 2025065 
                      (FPCore (re im)
                        :name "math.sqrt on complex, real part"
                        :precision binary64
                      
                        :alt
                        (! :herbie-platform default (if (< re 0) (* 1/2 (* (sqrt 2) (sqrt (/ (* im im) (- (modulus re im) re))))) (* 1/2 (sqrt (* 2 (+ (modulus re im) re))))))
                      
                        (* 0.5 (sqrt (* 2.0 (+ (sqrt (+ (* re re) (* im im))) re)))))