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

Percentage Accurate: 41.8% → 73.8%
Time: 2.3s
Alternatives: 8
Speedup: 2.5×

Specification

?
\[im > 0\]
\[\frac{1}{2} \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)} \]
(FPCore (re im)
  :precision binary64
  (* 1/2 (sqrt (* 2 (- (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[(1/2 * N[Sqrt[N[(2 * N[(N[Sqrt[N[(N[(re * re), $MachinePrecision] + N[(im * im), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\frac{1}{2} \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)}

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 8 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.8% accurate, 1.0× speedup?

\[\frac{1}{2} \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)} \]
(FPCore (re im)
  :precision binary64
  (* 1/2 (sqrt (* 2 (- (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[(1/2 * N[Sqrt[N[(2 * N[(N[Sqrt[N[(N[(re * re), $MachinePrecision] + N[(im * im), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\frac{1}{2} \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)}

Alternative 1: 73.8% accurate, 0.8× speedup?

\[\begin{array}{l} \mathbf{if}\;re \leq -3199999999999999787627735359118791747552630218171077842525632124659835956804589448297552398506401745056568866397772249313852982157676790821687394304:\\ \;\;\;\;\frac{1}{2} \cdot \sqrt{-4 \cdot re}\\ \mathbf{elif}\;re \leq \frac{-8924236958169793}{13729595320261219429963801598162786434538870600286610818788926918371086366795312104245119281322909109954592622782961716074243975999433287625148056582230114304}:\\ \;\;\;\;\frac{1}{2} \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)}\\ \mathbf{elif}\;re \leq 349999999999999977082398796899540174385819355252213370164883576067233347140147216384:\\ \;\;\;\;\sqrt{im + im} \cdot \frac{1}{2}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{2} \cdot \sqrt{\frac{im}{re} \cdot im}\\ \end{array} \]
(FPCore (re im)
  :precision binary64
  (if (<=
     re
     -3199999999999999787627735359118791747552630218171077842525632124659835956804589448297552398506401745056568866397772249313852982157676790821687394304)
  (* 1/2 (sqrt (* -4 re)))
  (if (<=
       re
       -8924236958169793/13729595320261219429963801598162786434538870600286610818788926918371086366795312104245119281322909109954592622782961716074243975999433287625148056582230114304)
    (* 1/2 (sqrt (* 2 (- (sqrt (+ (* re re) (* im im))) re))))
    (if (<=
         re
         349999999999999977082398796899540174385819355252213370164883576067233347140147216384)
      (* (sqrt (+ im im)) 1/2)
      (* 1/2 (sqrt (* (/ im re) im)))))))
double code(double re, double im) {
	double tmp;
	if (re <= -3.2e+147) {
		tmp = 0.5 * sqrt((-4.0 * re));
	} else if (re <= -6.5e-142) {
		tmp = 0.5 * sqrt((2.0 * (sqrt(((re * re) + (im * im))) - re)));
	} else if (re <= 3.5e+83) {
		tmp = sqrt((im + im)) * 0.5;
	} else {
		tmp = 0.5 * sqrt(((im / re) * im));
	}
	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 <= (-3.2d+147)) then
        tmp = 0.5d0 * sqrt(((-4.0d0) * re))
    else if (re <= (-6.5d-142)) then
        tmp = 0.5d0 * sqrt((2.0d0 * (sqrt(((re * re) + (im * im))) - re)))
    else if (re <= 3.5d+83) then
        tmp = sqrt((im + im)) * 0.5d0
    else
        tmp = 0.5d0 * sqrt(((im / re) * im))
    end if
    code = tmp
end function
public static double code(double re, double im) {
	double tmp;
	if (re <= -3.2e+147) {
		tmp = 0.5 * Math.sqrt((-4.0 * re));
	} else if (re <= -6.5e-142) {
		tmp = 0.5 * Math.sqrt((2.0 * (Math.sqrt(((re * re) + (im * im))) - re)));
	} else if (re <= 3.5e+83) {
		tmp = Math.sqrt((im + im)) * 0.5;
	} else {
		tmp = 0.5 * Math.sqrt(((im / re) * im));
	}
	return tmp;
}
def code(re, im):
	tmp = 0
	if re <= -3.2e+147:
		tmp = 0.5 * math.sqrt((-4.0 * re))
	elif re <= -6.5e-142:
		tmp = 0.5 * math.sqrt((2.0 * (math.sqrt(((re * re) + (im * im))) - re)))
	elif re <= 3.5e+83:
		tmp = math.sqrt((im + im)) * 0.5
	else:
		tmp = 0.5 * math.sqrt(((im / re) * im))
	return tmp
function code(re, im)
	tmp = 0.0
	if (re <= -3.2e+147)
		tmp = Float64(0.5 * sqrt(Float64(-4.0 * re)));
	elseif (re <= -6.5e-142)
		tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(sqrt(Float64(Float64(re * re) + Float64(im * im))) - re))));
	elseif (re <= 3.5e+83)
		tmp = Float64(sqrt(Float64(im + im)) * 0.5);
	else
		tmp = Float64(0.5 * sqrt(Float64(Float64(im / re) * im)));
	end
	return tmp
end
function tmp_2 = code(re, im)
	tmp = 0.0;
	if (re <= -3.2e+147)
		tmp = 0.5 * sqrt((-4.0 * re));
	elseif (re <= -6.5e-142)
		tmp = 0.5 * sqrt((2.0 * (sqrt(((re * re) + (im * im))) - re)));
	elseif (re <= 3.5e+83)
		tmp = sqrt((im + im)) * 0.5;
	else
		tmp = 0.5 * sqrt(((im / re) * im));
	end
	tmp_2 = tmp;
end
code[re_, im_] := If[LessEqual[re, -3199999999999999787627735359118791747552630218171077842525632124659835956804589448297552398506401745056568866397772249313852982157676790821687394304], N[(1/2 * N[Sqrt[N[(-4 * re), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, -8924236958169793/13729595320261219429963801598162786434538870600286610818788926918371086366795312104245119281322909109954592622782961716074243975999433287625148056582230114304], N[(1/2 * N[Sqrt[N[(2 * N[(N[Sqrt[N[(N[(re * re), $MachinePrecision] + N[(im * im), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 349999999999999977082398796899540174385819355252213370164883576067233347140147216384], N[(N[Sqrt[N[(im + im), $MachinePrecision]], $MachinePrecision] * 1/2), $MachinePrecision], N[(1/2 * N[Sqrt[N[(N[(im / re), $MachinePrecision] * im), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\mathbf{if}\;re \leq -3199999999999999787627735359118791747552630218171077842525632124659835956804589448297552398506401745056568866397772249313852982157676790821687394304:\\
\;\;\;\;\frac{1}{2} \cdot \sqrt{-4 \cdot re}\\

\mathbf{elif}\;re \leq \frac{-8924236958169793}{13729595320261219429963801598162786434538870600286610818788926918371086366795312104245119281322909109954592622782961716074243975999433287625148056582230114304}:\\
\;\;\;\;\frac{1}{2} \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)}\\

\mathbf{elif}\;re \leq 349999999999999977082398796899540174385819355252213370164883576067233347140147216384:\\
\;\;\;\;\sqrt{im + im} \cdot \frac{1}{2}\\

\mathbf{else}:\\
\;\;\;\;\frac{1}{2} \cdot \sqrt{\frac{im}{re} \cdot im}\\


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

    1. Initial program 41.8%

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

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

        \[\leadsto \frac{1}{2} \cdot \sqrt{-4 \cdot \color{blue}{re}} \]
    4. Applied rewrites27.6%

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

    if -3.1999999999999998e147 < re < -6.5000000000000003e-142

    1. Initial program 41.8%

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

    if -6.5000000000000003e-142 < re < 3.4999999999999998e83

    1. Initial program 41.8%

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

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

        \[\leadsto \frac{1}{2} \cdot \sqrt{2 \cdot \color{blue}{im}} \]
    4. Applied rewrites51.5%

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

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

        \[\leadsto \color{blue}{\sqrt{2 \cdot im} \cdot \frac{1}{2}} \]
      3. lower-*.f6451.5%

        \[\leadsto \color{blue}{\sqrt{2 \cdot im} \cdot \frac{1}{2}} \]
      4. lift-*.f64N/A

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

        \[\leadsto \sqrt{im + \color{blue}{im}} \cdot \frac{1}{2} \]
      6. lower-+.f6451.5%

        \[\leadsto \sqrt{im + \color{blue}{im}} \cdot \frac{1}{2} \]
    6. Applied rewrites51.5%

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

    if 3.4999999999999998e83 < re

    1. Initial program 41.8%

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

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

        \[\leadsto \frac{1}{2} \cdot \sqrt{\frac{{im}^{2}}{\color{blue}{re}}} \]
      2. lower-pow.f6414.5%

        \[\leadsto \frac{1}{2} \cdot \sqrt{\frac{{im}^{2}}{re}} \]
    4. Applied rewrites14.5%

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

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

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

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

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

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

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

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

        \[\leadsto \frac{1}{2} \cdot \sqrt{\frac{im}{re} \cdot im} \]
      9. lower-/.f6417.3%

        \[\leadsto \frac{1}{2} \cdot \sqrt{\frac{im}{re} \cdot im} \]
    6. Applied rewrites17.3%

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

Alternative 2: 71.0% accurate, 0.9× speedup?

\[\begin{array}{l} \mathbf{if}\;re \leq -19000000000000001018918648858612766219271529294930202244204011192320:\\ \;\;\;\;\frac{1}{2} \cdot \sqrt{-4 \cdot re}\\ \mathbf{elif}\;re \leq 339999999999999984815804307206829625576824593371778690788974276089217024:\\ \;\;\;\;\sqrt{\left(im - re\right) \cdot 2} \cdot \frac{1}{2}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{\frac{im}{\frac{re}{im}}} \cdot \frac{1}{2}\\ \end{array} \]
(FPCore (re im)
  :precision binary64
  (if (<=
     re
     -19000000000000001018918648858612766219271529294930202244204011192320)
  (* 1/2 (sqrt (* -4 re)))
  (if (<=
       re
       339999999999999984815804307206829625576824593371778690788974276089217024)
    (* (sqrt (* (- im re) 2)) 1/2)
    (* (sqrt (/ im (/ re im))) 1/2))))
double code(double re, double im) {
	double tmp;
	if (re <= -1.9e+67) {
		tmp = 0.5 * sqrt((-4.0 * re));
	} else if (re <= 3.4e+71) {
		tmp = sqrt(((im - re) * 2.0)) * 0.5;
	} else {
		tmp = sqrt((im / (re / 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 <= (-1.9d+67)) then
        tmp = 0.5d0 * sqrt(((-4.0d0) * re))
    else if (re <= 3.4d+71) then
        tmp = sqrt(((im - re) * 2.0d0)) * 0.5d0
    else
        tmp = sqrt((im / (re / im))) * 0.5d0
    end if
    code = tmp
end function
public static double code(double re, double im) {
	double tmp;
	if (re <= -1.9e+67) {
		tmp = 0.5 * Math.sqrt((-4.0 * re));
	} else if (re <= 3.4e+71) {
		tmp = Math.sqrt(((im - re) * 2.0)) * 0.5;
	} else {
		tmp = Math.sqrt((im / (re / im))) * 0.5;
	}
	return tmp;
}
def code(re, im):
	tmp = 0
	if re <= -1.9e+67:
		tmp = 0.5 * math.sqrt((-4.0 * re))
	elif re <= 3.4e+71:
		tmp = math.sqrt(((im - re) * 2.0)) * 0.5
	else:
		tmp = math.sqrt((im / (re / im))) * 0.5
	return tmp
function code(re, im)
	tmp = 0.0
	if (re <= -1.9e+67)
		tmp = Float64(0.5 * sqrt(Float64(-4.0 * re)));
	elseif (re <= 3.4e+71)
		tmp = Float64(sqrt(Float64(Float64(im - re) * 2.0)) * 0.5);
	else
		tmp = Float64(sqrt(Float64(im / Float64(re / im))) * 0.5);
	end
	return tmp
end
function tmp_2 = code(re, im)
	tmp = 0.0;
	if (re <= -1.9e+67)
		tmp = 0.5 * sqrt((-4.0 * re));
	elseif (re <= 3.4e+71)
		tmp = sqrt(((im - re) * 2.0)) * 0.5;
	else
		tmp = sqrt((im / (re / im))) * 0.5;
	end
	tmp_2 = tmp;
end
code[re_, im_] := If[LessEqual[re, -19000000000000001018918648858612766219271529294930202244204011192320], N[(1/2 * N[Sqrt[N[(-4 * re), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 339999999999999984815804307206829625576824593371778690788974276089217024], N[(N[Sqrt[N[(N[(im - re), $MachinePrecision] * 2), $MachinePrecision]], $MachinePrecision] * 1/2), $MachinePrecision], N[(N[Sqrt[N[(im / N[(re / im), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * 1/2), $MachinePrecision]]]
\begin{array}{l}
\mathbf{if}\;re \leq -19000000000000001018918648858612766219271529294930202244204011192320:\\
\;\;\;\;\frac{1}{2} \cdot \sqrt{-4 \cdot re}\\

\mathbf{elif}\;re \leq 339999999999999984815804307206829625576824593371778690788974276089217024:\\
\;\;\;\;\sqrt{\left(im - re\right) \cdot 2} \cdot \frac{1}{2}\\

\mathbf{else}:\\
\;\;\;\;\sqrt{\frac{im}{\frac{re}{im}}} \cdot \frac{1}{2}\\


\end{array}
Derivation
  1. Split input into 3 regimes
  2. if re < -1.9000000000000001e67

    1. Initial program 41.8%

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

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

        \[\leadsto \frac{1}{2} \cdot \sqrt{-4 \cdot \color{blue}{re}} \]
    4. Applied rewrites27.6%

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

    if -1.9000000000000001e67 < re < 3.3999999999999998e71

    1. Initial program 41.8%

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\sqrt{im \cdot \left(2 + -2 \cdot \frac{re}{im}\right)} \cdot \frac{1}{2}} \]
    6. Applied rewrites54.1%

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

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

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

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

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

        \[\leadsto \sqrt{2 \cdot im - 2 \cdot \color{blue}{re}} \cdot \frac{1}{2} \]
      6. distribute-lft-out--N/A

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

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

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

        \[\leadsto \sqrt{\left(im - re\right) \cdot 2} \cdot \frac{1}{2} \]
    8. Applied rewrites54.1%

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

    if 3.3999999999999998e71 < re

    1. Initial program 41.8%

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

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

        \[\leadsto \frac{1}{2} \cdot \sqrt{\frac{{im}^{2}}{\color{blue}{re}}} \]
      2. lower-pow.f6414.5%

        \[\leadsto \frac{1}{2} \cdot \sqrt{\frac{{im}^{2}}{re}} \]
    4. Applied rewrites14.5%

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

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

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

        \[\leadsto \color{blue}{\sqrt{\frac{{im}^{2}}{re}} \cdot \frac{1}{2}} \]
      4. lift-pow.f64N/A

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

        \[\leadsto \sqrt{\frac{im \cdot im}{re}} \cdot \frac{1}{2} \]
      6. lower-*.f6414.5%

        \[\leadsto \sqrt{\frac{im \cdot im}{re}} \cdot \frac{1}{2} \]
    6. Applied rewrites14.5%

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

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

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

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

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

        \[\leadsto \sqrt{\frac{im}{\frac{re}{\color{blue}{im}}}} \cdot \frac{1}{2} \]
      6. lower-/.f6417.3%

        \[\leadsto \sqrt{\frac{im}{\color{blue}{\frac{re}{im}}}} \cdot \frac{1}{2} \]
    8. Applied rewrites17.3%

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

Alternative 3: 71.0% accurate, 0.9× speedup?

\[\begin{array}{l} \mathbf{if}\;re \leq -19000000000000001018918648858612766219271529294930202244204011192320:\\ \;\;\;\;\frac{1}{2} \cdot \sqrt{-4 \cdot re}\\ \mathbf{elif}\;re \leq 339999999999999984815804307206829625576824593371778690788974276089217024:\\ \;\;\;\;\frac{1}{2} \cdot \sqrt{im \cdot \left(2 + -2 \cdot \frac{re}{im}\right)}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{\frac{im}{\frac{re}{im}}} \cdot \frac{1}{2}\\ \end{array} \]
(FPCore (re im)
  :precision binary64
  (if (<=
     re
     -19000000000000001018918648858612766219271529294930202244204011192320)
  (* 1/2 (sqrt (* -4 re)))
  (if (<=
       re
       339999999999999984815804307206829625576824593371778690788974276089217024)
    (* 1/2 (sqrt (* im (+ 2 (* -2 (/ re im))))))
    (* (sqrt (/ im (/ re im))) 1/2))))
double code(double re, double im) {
	double tmp;
	if (re <= -1.9e+67) {
		tmp = 0.5 * sqrt((-4.0 * re));
	} else if (re <= 3.4e+71) {
		tmp = 0.5 * sqrt((im * (2.0 + (-2.0 * (re / im)))));
	} else {
		tmp = sqrt((im / (re / 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 <= (-1.9d+67)) then
        tmp = 0.5d0 * sqrt(((-4.0d0) * re))
    else if (re <= 3.4d+71) then
        tmp = 0.5d0 * sqrt((im * (2.0d0 + ((-2.0d0) * (re / im)))))
    else
        tmp = sqrt((im / (re / im))) * 0.5d0
    end if
    code = tmp
end function
public static double code(double re, double im) {
	double tmp;
	if (re <= -1.9e+67) {
		tmp = 0.5 * Math.sqrt((-4.0 * re));
	} else if (re <= 3.4e+71) {
		tmp = 0.5 * Math.sqrt((im * (2.0 + (-2.0 * (re / im)))));
	} else {
		tmp = Math.sqrt((im / (re / im))) * 0.5;
	}
	return tmp;
}
def code(re, im):
	tmp = 0
	if re <= -1.9e+67:
		tmp = 0.5 * math.sqrt((-4.0 * re))
	elif re <= 3.4e+71:
		tmp = 0.5 * math.sqrt((im * (2.0 + (-2.0 * (re / im)))))
	else:
		tmp = math.sqrt((im / (re / im))) * 0.5
	return tmp
function code(re, im)
	tmp = 0.0
	if (re <= -1.9e+67)
		tmp = Float64(0.5 * sqrt(Float64(-4.0 * re)));
	elseif (re <= 3.4e+71)
		tmp = Float64(0.5 * sqrt(Float64(im * Float64(2.0 + Float64(-2.0 * Float64(re / im))))));
	else
		tmp = Float64(sqrt(Float64(im / Float64(re / im))) * 0.5);
	end
	return tmp
end
function tmp_2 = code(re, im)
	tmp = 0.0;
	if (re <= -1.9e+67)
		tmp = 0.5 * sqrt((-4.0 * re));
	elseif (re <= 3.4e+71)
		tmp = 0.5 * sqrt((im * (2.0 + (-2.0 * (re / im)))));
	else
		tmp = sqrt((im / (re / im))) * 0.5;
	end
	tmp_2 = tmp;
end
code[re_, im_] := If[LessEqual[re, -19000000000000001018918648858612766219271529294930202244204011192320], N[(1/2 * N[Sqrt[N[(-4 * re), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 339999999999999984815804307206829625576824593371778690788974276089217024], N[(1/2 * N[Sqrt[N[(im * N[(2 + N[(-2 * N[(re / im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(N[Sqrt[N[(im / N[(re / im), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * 1/2), $MachinePrecision]]]
\begin{array}{l}
\mathbf{if}\;re \leq -19000000000000001018918648858612766219271529294930202244204011192320:\\
\;\;\;\;\frac{1}{2} \cdot \sqrt{-4 \cdot re}\\

\mathbf{elif}\;re \leq 339999999999999984815804307206829625576824593371778690788974276089217024:\\
\;\;\;\;\frac{1}{2} \cdot \sqrt{im \cdot \left(2 + -2 \cdot \frac{re}{im}\right)}\\

\mathbf{else}:\\
\;\;\;\;\sqrt{\frac{im}{\frac{re}{im}}} \cdot \frac{1}{2}\\


\end{array}
Derivation
  1. Split input into 3 regimes
  2. if re < -1.9000000000000001e67

    1. Initial program 41.8%

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

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

        \[\leadsto \frac{1}{2} \cdot \sqrt{-4 \cdot \color{blue}{re}} \]
    4. Applied rewrites27.6%

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

    if -1.9000000000000001e67 < re < 3.3999999999999998e71

    1. Initial program 41.8%

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

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

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

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

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

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

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

    if 3.3999999999999998e71 < re

    1. Initial program 41.8%

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

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

        \[\leadsto \frac{1}{2} \cdot \sqrt{\frac{{im}^{2}}{\color{blue}{re}}} \]
      2. lower-pow.f6414.5%

        \[\leadsto \frac{1}{2} \cdot \sqrt{\frac{{im}^{2}}{re}} \]
    4. Applied rewrites14.5%

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

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

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

        \[\leadsto \color{blue}{\sqrt{\frac{{im}^{2}}{re}} \cdot \frac{1}{2}} \]
      4. lift-pow.f64N/A

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

        \[\leadsto \sqrt{\frac{im \cdot im}{re}} \cdot \frac{1}{2} \]
      6. lower-*.f6414.5%

        \[\leadsto \sqrt{\frac{im \cdot im}{re}} \cdot \frac{1}{2} \]
    6. Applied rewrites14.5%

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

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

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

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

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

        \[\leadsto \sqrt{\frac{im}{\frac{re}{\color{blue}{im}}}} \cdot \frac{1}{2} \]
      6. lower-/.f6417.3%

        \[\leadsto \sqrt{\frac{im}{\color{blue}{\frac{re}{im}}}} \cdot \frac{1}{2} \]
    8. Applied rewrites17.3%

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

Alternative 4: 71.0% accurate, 1.1× speedup?

\[\begin{array}{l} \mathbf{if}\;re \leq -19000000000000001018918648858612766219271529294930202244204011192320:\\ \;\;\;\;\frac{1}{2} \cdot \sqrt{-4 \cdot re}\\ \mathbf{elif}\;re \leq 339999999999999984815804307206829625576824593371778690788974276089217024:\\ \;\;\;\;\sqrt{\left(im - re\right) \cdot 2} \cdot \frac{1}{2}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{2} \cdot \sqrt{\frac{im}{re} \cdot im}\\ \end{array} \]
(FPCore (re im)
  :precision binary64
  (if (<=
     re
     -19000000000000001018918648858612766219271529294930202244204011192320)
  (* 1/2 (sqrt (* -4 re)))
  (if (<=
       re
       339999999999999984815804307206829625576824593371778690788974276089217024)
    (* (sqrt (* (- im re) 2)) 1/2)
    (* 1/2 (sqrt (* (/ im re) im))))))
double code(double re, double im) {
	double tmp;
	if (re <= -1.9e+67) {
		tmp = 0.5 * sqrt((-4.0 * re));
	} else if (re <= 3.4e+71) {
		tmp = sqrt(((im - re) * 2.0)) * 0.5;
	} else {
		tmp = 0.5 * sqrt(((im / re) * im));
	}
	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 <= (-1.9d+67)) then
        tmp = 0.5d0 * sqrt(((-4.0d0) * re))
    else if (re <= 3.4d+71) then
        tmp = sqrt(((im - re) * 2.0d0)) * 0.5d0
    else
        tmp = 0.5d0 * sqrt(((im / re) * im))
    end if
    code = tmp
end function
public static double code(double re, double im) {
	double tmp;
	if (re <= -1.9e+67) {
		tmp = 0.5 * Math.sqrt((-4.0 * re));
	} else if (re <= 3.4e+71) {
		tmp = Math.sqrt(((im - re) * 2.0)) * 0.5;
	} else {
		tmp = 0.5 * Math.sqrt(((im / re) * im));
	}
	return tmp;
}
def code(re, im):
	tmp = 0
	if re <= -1.9e+67:
		tmp = 0.5 * math.sqrt((-4.0 * re))
	elif re <= 3.4e+71:
		tmp = math.sqrt(((im - re) * 2.0)) * 0.5
	else:
		tmp = 0.5 * math.sqrt(((im / re) * im))
	return tmp
function code(re, im)
	tmp = 0.0
	if (re <= -1.9e+67)
		tmp = Float64(0.5 * sqrt(Float64(-4.0 * re)));
	elseif (re <= 3.4e+71)
		tmp = Float64(sqrt(Float64(Float64(im - re) * 2.0)) * 0.5);
	else
		tmp = Float64(0.5 * sqrt(Float64(Float64(im / re) * im)));
	end
	return tmp
end
function tmp_2 = code(re, im)
	tmp = 0.0;
	if (re <= -1.9e+67)
		tmp = 0.5 * sqrt((-4.0 * re));
	elseif (re <= 3.4e+71)
		tmp = sqrt(((im - re) * 2.0)) * 0.5;
	else
		tmp = 0.5 * sqrt(((im / re) * im));
	end
	tmp_2 = tmp;
end
code[re_, im_] := If[LessEqual[re, -19000000000000001018918648858612766219271529294930202244204011192320], N[(1/2 * N[Sqrt[N[(-4 * re), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 339999999999999984815804307206829625576824593371778690788974276089217024], N[(N[Sqrt[N[(N[(im - re), $MachinePrecision] * 2), $MachinePrecision]], $MachinePrecision] * 1/2), $MachinePrecision], N[(1/2 * N[Sqrt[N[(N[(im / re), $MachinePrecision] * im), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\mathbf{if}\;re \leq -19000000000000001018918648858612766219271529294930202244204011192320:\\
\;\;\;\;\frac{1}{2} \cdot \sqrt{-4 \cdot re}\\

\mathbf{elif}\;re \leq 339999999999999984815804307206829625576824593371778690788974276089217024:\\
\;\;\;\;\sqrt{\left(im - re\right) \cdot 2} \cdot \frac{1}{2}\\

\mathbf{else}:\\
\;\;\;\;\frac{1}{2} \cdot \sqrt{\frac{im}{re} \cdot im}\\


\end{array}
Derivation
  1. Split input into 3 regimes
  2. if re < -1.9000000000000001e67

    1. Initial program 41.8%

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

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

        \[\leadsto \frac{1}{2} \cdot \sqrt{-4 \cdot \color{blue}{re}} \]
    4. Applied rewrites27.6%

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

    if -1.9000000000000001e67 < re < 3.3999999999999998e71

    1. Initial program 41.8%

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\sqrt{im \cdot \left(2 + -2 \cdot \frac{re}{im}\right)} \cdot \frac{1}{2}} \]
    6. Applied rewrites54.1%

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

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

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

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

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

        \[\leadsto \sqrt{2 \cdot im - 2 \cdot \color{blue}{re}} \cdot \frac{1}{2} \]
      6. distribute-lft-out--N/A

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

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

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

        \[\leadsto \sqrt{\left(im - re\right) \cdot 2} \cdot \frac{1}{2} \]
    8. Applied rewrites54.1%

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

    if 3.3999999999999998e71 < re

    1. Initial program 41.8%

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

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

        \[\leadsto \frac{1}{2} \cdot \sqrt{\frac{{im}^{2}}{\color{blue}{re}}} \]
      2. lower-pow.f6414.5%

        \[\leadsto \frac{1}{2} \cdot \sqrt{\frac{{im}^{2}}{re}} \]
    4. Applied rewrites14.5%

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

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

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

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

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

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

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

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

        \[\leadsto \frac{1}{2} \cdot \sqrt{\frac{im}{re} \cdot im} \]
      9. lower-/.f6417.3%

        \[\leadsto \frac{1}{2} \cdot \sqrt{\frac{im}{re} \cdot im} \]
    6. Applied rewrites17.3%

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

Alternative 5: 63.8% accurate, 1.2× speedup?

\[\begin{array}{l} t_0 := \frac{1}{2} \cdot \sqrt{-4 \cdot re}\\ \mathbf{if}\;re \leq -19000000000000001018918648858612766219271529294930202244204011192320:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;re \leq \frac{-207784017051299}{76957043352332967211482500195592995713046365762627825523336510555167425334955489475418488779072100860950445293568}:\\ \;\;\;\;\sqrt{\left(im - re\right) \cdot 2} \cdot \frac{1}{2}\\ \mathbf{elif}\;re \leq \frac{-8924236958169793}{13729595320261219429963801598162786434538870600286610818788926918371086366795312104245119281322909109954592622782961716074243975999433287625148056582230114304}:\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;\sqrt{im + im} \cdot \frac{1}{2}\\ \end{array} \]
(FPCore (re im)
  :precision binary64
  (let* ((t_0 (* 1/2 (sqrt (* -4 re)))))
  (if (<=
       re
       -19000000000000001018918648858612766219271529294930202244204011192320)
    t_0
    (if (<=
         re
         -207784017051299/76957043352332967211482500195592995713046365762627825523336510555167425334955489475418488779072100860950445293568)
      (* (sqrt (* (- im re) 2)) 1/2)
      (if (<=
           re
           -8924236958169793/13729595320261219429963801598162786434538870600286610818788926918371086366795312104245119281322909109954592622782961716074243975999433287625148056582230114304)
        t_0
        (* (sqrt (+ im im)) 1/2))))))
double code(double re, double im) {
	double t_0 = 0.5 * sqrt((-4.0 * re));
	double tmp;
	if (re <= -1.9e+67) {
		tmp = t_0;
	} else if (re <= -2.7e-99) {
		tmp = sqrt(((im - re) * 2.0)) * 0.5;
	} else if (re <= -6.5e-142) {
		tmp = t_0;
	} 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) :: t_0
    real(8) :: tmp
    t_0 = 0.5d0 * sqrt(((-4.0d0) * re))
    if (re <= (-1.9d+67)) then
        tmp = t_0
    else if (re <= (-2.7d-99)) then
        tmp = sqrt(((im - re) * 2.0d0)) * 0.5d0
    else if (re <= (-6.5d-142)) then
        tmp = t_0
    else
        tmp = sqrt((im + im)) * 0.5d0
    end if
    code = tmp
end function
public static double code(double re, double im) {
	double t_0 = 0.5 * Math.sqrt((-4.0 * re));
	double tmp;
	if (re <= -1.9e+67) {
		tmp = t_0;
	} else if (re <= -2.7e-99) {
		tmp = Math.sqrt(((im - re) * 2.0)) * 0.5;
	} else if (re <= -6.5e-142) {
		tmp = t_0;
	} else {
		tmp = Math.sqrt((im + im)) * 0.5;
	}
	return tmp;
}
def code(re, im):
	t_0 = 0.5 * math.sqrt((-4.0 * re))
	tmp = 0
	if re <= -1.9e+67:
		tmp = t_0
	elif re <= -2.7e-99:
		tmp = math.sqrt(((im - re) * 2.0)) * 0.5
	elif re <= -6.5e-142:
		tmp = t_0
	else:
		tmp = math.sqrt((im + im)) * 0.5
	return tmp
function code(re, im)
	t_0 = Float64(0.5 * sqrt(Float64(-4.0 * re)))
	tmp = 0.0
	if (re <= -1.9e+67)
		tmp = t_0;
	elseif (re <= -2.7e-99)
		tmp = Float64(sqrt(Float64(Float64(im - re) * 2.0)) * 0.5);
	elseif (re <= -6.5e-142)
		tmp = t_0;
	else
		tmp = Float64(sqrt(Float64(im + im)) * 0.5);
	end
	return tmp
end
function tmp_2 = code(re, im)
	t_0 = 0.5 * sqrt((-4.0 * re));
	tmp = 0.0;
	if (re <= -1.9e+67)
		tmp = t_0;
	elseif (re <= -2.7e-99)
		tmp = sqrt(((im - re) * 2.0)) * 0.5;
	elseif (re <= -6.5e-142)
		tmp = t_0;
	else
		tmp = sqrt((im + im)) * 0.5;
	end
	tmp_2 = tmp;
end
code[re_, im_] := Block[{t$95$0 = N[(1/2 * N[Sqrt[N[(-4 * re), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[re, -19000000000000001018918648858612766219271529294930202244204011192320], t$95$0, If[LessEqual[re, -207784017051299/76957043352332967211482500195592995713046365762627825523336510555167425334955489475418488779072100860950445293568], N[(N[Sqrt[N[(N[(im - re), $MachinePrecision] * 2), $MachinePrecision]], $MachinePrecision] * 1/2), $MachinePrecision], If[LessEqual[re, -8924236958169793/13729595320261219429963801598162786434538870600286610818788926918371086366795312104245119281322909109954592622782961716074243975999433287625148056582230114304], t$95$0, N[(N[Sqrt[N[(im + im), $MachinePrecision]], $MachinePrecision] * 1/2), $MachinePrecision]]]]]
\begin{array}{l}
t_0 := \frac{1}{2} \cdot \sqrt{-4 \cdot re}\\
\mathbf{if}\;re \leq -19000000000000001018918648858612766219271529294930202244204011192320:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;re \leq \frac{-207784017051299}{76957043352332967211482500195592995713046365762627825523336510555167425334955489475418488779072100860950445293568}:\\
\;\;\;\;\sqrt{\left(im - re\right) \cdot 2} \cdot \frac{1}{2}\\

\mathbf{elif}\;re \leq \frac{-8924236958169793}{13729595320261219429963801598162786434538870600286610818788926918371086366795312104245119281322909109954592622782961716074243975999433287625148056582230114304}:\\
\;\;\;\;t\_0\\

\mathbf{else}:\\
\;\;\;\;\sqrt{im + im} \cdot \frac{1}{2}\\


\end{array}
Derivation
  1. Split input into 3 regimes
  2. if re < -1.9000000000000001e67 or -2.6999999999999999e-99 < re < -6.5000000000000003e-142

    1. Initial program 41.8%

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

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

        \[\leadsto \frac{1}{2} \cdot \sqrt{-4 \cdot \color{blue}{re}} \]
    4. Applied rewrites27.6%

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

    if -1.9000000000000001e67 < re < -2.6999999999999999e-99

    1. Initial program 41.8%

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\sqrt{im \cdot \left(2 + -2 \cdot \frac{re}{im}\right)} \cdot \frac{1}{2}} \]
    6. Applied rewrites54.1%

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

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

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

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

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

        \[\leadsto \sqrt{2 \cdot im - 2 \cdot \color{blue}{re}} \cdot \frac{1}{2} \]
      6. distribute-lft-out--N/A

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

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

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

        \[\leadsto \sqrt{\left(im - re\right) \cdot 2} \cdot \frac{1}{2} \]
    8. Applied rewrites54.1%

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

    if -6.5000000000000003e-142 < re

    1. Initial program 41.8%

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

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

        \[\leadsto \frac{1}{2} \cdot \sqrt{2 \cdot \color{blue}{im}} \]
    4. Applied rewrites51.5%

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

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

        \[\leadsto \color{blue}{\sqrt{2 \cdot im} \cdot \frac{1}{2}} \]
      3. lower-*.f6451.5%

        \[\leadsto \color{blue}{\sqrt{2 \cdot im} \cdot \frac{1}{2}} \]
      4. lift-*.f64N/A

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

        \[\leadsto \sqrt{im + \color{blue}{im}} \cdot \frac{1}{2} \]
      6. lower-+.f6451.5%

        \[\leadsto \sqrt{im + \color{blue}{im}} \cdot \frac{1}{2} \]
    6. Applied rewrites51.5%

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

Alternative 6: 63.5% accurate, 1.7× speedup?

\[\begin{array}{l} \mathbf{if}\;re \leq -61000000000000001154395395843627917390008246875717559787641110528:\\ \;\;\;\;\frac{1}{2} \cdot \sqrt{-4 \cdot re}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{im + im} \cdot \frac{1}{2}\\ \end{array} \]
(FPCore (re im)
  :precision binary64
  (if (<=
     re
     -61000000000000001154395395843627917390008246875717559787641110528)
  (* 1/2 (sqrt (* -4 re)))
  (* (sqrt (+ im im)) 1/2)))
double code(double re, double im) {
	double tmp;
	if (re <= -6.1e+64) {
		tmp = 0.5 * sqrt((-4.0 * re));
	} 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 <= (-6.1d+64)) then
        tmp = 0.5d0 * sqrt(((-4.0d0) * re))
    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 <= -6.1e+64) {
		tmp = 0.5 * Math.sqrt((-4.0 * re));
	} else {
		tmp = Math.sqrt((im + im)) * 0.5;
	}
	return tmp;
}
def code(re, im):
	tmp = 0
	if re <= -6.1e+64:
		tmp = 0.5 * math.sqrt((-4.0 * re))
	else:
		tmp = math.sqrt((im + im)) * 0.5
	return tmp
function code(re, im)
	tmp = 0.0
	if (re <= -6.1e+64)
		tmp = Float64(0.5 * sqrt(Float64(-4.0 * re)));
	else
		tmp = Float64(sqrt(Float64(im + im)) * 0.5);
	end
	return tmp
end
function tmp_2 = code(re, im)
	tmp = 0.0;
	if (re <= -6.1e+64)
		tmp = 0.5 * sqrt((-4.0 * re));
	else
		tmp = sqrt((im + im)) * 0.5;
	end
	tmp_2 = tmp;
end
code[re_, im_] := If[LessEqual[re, -61000000000000001154395395843627917390008246875717559787641110528], N[(1/2 * N[Sqrt[N[(-4 * re), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(N[Sqrt[N[(im + im), $MachinePrecision]], $MachinePrecision] * 1/2), $MachinePrecision]]
\begin{array}{l}
\mathbf{if}\;re \leq -61000000000000001154395395843627917390008246875717559787641110528:\\
\;\;\;\;\frac{1}{2} \cdot \sqrt{-4 \cdot re}\\

\mathbf{else}:\\
\;\;\;\;\sqrt{im + im} \cdot \frac{1}{2}\\


\end{array}
Derivation
  1. Split input into 2 regimes
  2. if re < -6.1000000000000001e64

    1. Initial program 41.8%

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

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

        \[\leadsto \frac{1}{2} \cdot \sqrt{-4 \cdot \color{blue}{re}} \]
    4. Applied rewrites27.6%

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

    if -6.1000000000000001e64 < re

    1. Initial program 41.8%

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

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

        \[\leadsto \frac{1}{2} \cdot \sqrt{2 \cdot \color{blue}{im}} \]
    4. Applied rewrites51.5%

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

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

        \[\leadsto \color{blue}{\sqrt{2 \cdot im} \cdot \frac{1}{2}} \]
      3. lower-*.f6451.5%

        \[\leadsto \color{blue}{\sqrt{2 \cdot im} \cdot \frac{1}{2}} \]
      4. lift-*.f64N/A

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

        \[\leadsto \sqrt{im + \color{blue}{im}} \cdot \frac{1}{2} \]
      6. lower-+.f6451.5%

        \[\leadsto \sqrt{im + \color{blue}{im}} \cdot \frac{1}{2} \]
    6. Applied rewrites51.5%

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

Alternative 7: 52.8% accurate, 1.9× speedup?

\[\begin{array}{l} t_0 := \sqrt{im + im}\\ \mathbf{if}\;im \leq \frac{921786315201311}{1707011694817242694164442058424641996069058130512872489061441999811593532881313810309486643423117898430190057111918909554147533223454557460573019149396692491800360340355587726966548041193424390330615044130786970107312831497593974090537952608256}:\\ \;\;\;\;t\_0 \cdot 0\\ \mathbf{else}:\\ \;\;\;\;t\_0 \cdot \frac{1}{2}\\ \end{array} \]
(FPCore (re im)
  :precision binary64
  (let* ((t_0 (sqrt (+ im im))))
  (if (<=
       im
       921786315201311/1707011694817242694164442058424641996069058130512872489061441999811593532881313810309486643423117898430190057111918909554147533223454557460573019149396692491800360340355587726966548041193424390330615044130786970107312831497593974090537952608256)
    (* t_0 0)
    (* t_0 1/2))))
double code(double re, double im) {
	double t_0 = sqrt((im + im));
	double tmp;
	if (im <= 5.4e-229) {
		tmp = t_0 * 0.0;
	} else {
		tmp = t_0 * 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) :: t_0
    real(8) :: tmp
    t_0 = sqrt((im + im))
    if (im <= 5.4d-229) then
        tmp = t_0 * 0.0d0
    else
        tmp = t_0 * 0.5d0
    end if
    code = tmp
end function
public static double code(double re, double im) {
	double t_0 = Math.sqrt((im + im));
	double tmp;
	if (im <= 5.4e-229) {
		tmp = t_0 * 0.0;
	} else {
		tmp = t_0 * 0.5;
	}
	return tmp;
}
def code(re, im):
	t_0 = math.sqrt((im + im))
	tmp = 0
	if im <= 5.4e-229:
		tmp = t_0 * 0.0
	else:
		tmp = t_0 * 0.5
	return tmp
function code(re, im)
	t_0 = sqrt(Float64(im + im))
	tmp = 0.0
	if (im <= 5.4e-229)
		tmp = Float64(t_0 * 0.0);
	else
		tmp = Float64(t_0 * 0.5);
	end
	return tmp
end
function tmp_2 = code(re, im)
	t_0 = sqrt((im + im));
	tmp = 0.0;
	if (im <= 5.4e-229)
		tmp = t_0 * 0.0;
	else
		tmp = t_0 * 0.5;
	end
	tmp_2 = tmp;
end
code[re_, im_] := Block[{t$95$0 = N[Sqrt[N[(im + im), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[im, 921786315201311/1707011694817242694164442058424641996069058130512872489061441999811593532881313810309486643423117898430190057111918909554147533223454557460573019149396692491800360340355587726966548041193424390330615044130786970107312831497593974090537952608256], N[(t$95$0 * 0), $MachinePrecision], N[(t$95$0 * 1/2), $MachinePrecision]]]
\begin{array}{l}
t_0 := \sqrt{im + im}\\
\mathbf{if}\;im \leq \frac{921786315201311}{1707011694817242694164442058424641996069058130512872489061441999811593532881313810309486643423117898430190057111918909554147533223454557460573019149396692491800360340355587726966548041193424390330615044130786970107312831497593974090537952608256}:\\
\;\;\;\;t\_0 \cdot 0\\

\mathbf{else}:\\
\;\;\;\;t\_0 \cdot \frac{1}{2}\\


\end{array}
Derivation
  1. Split input into 2 regimes
  2. if im < 5.3999999999999997e-229

    1. Initial program 41.8%

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

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

        \[\leadsto \frac{1}{2} \cdot \sqrt{2 \cdot \color{blue}{im}} \]
    4. Applied rewrites51.5%

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

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

        \[\leadsto \color{blue}{\sqrt{2 \cdot im} \cdot \frac{1}{2}} \]
      3. lower-*.f6451.5%

        \[\leadsto \color{blue}{\sqrt{2 \cdot im} \cdot \frac{1}{2}} \]
      4. lift-*.f64N/A

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

        \[\leadsto \sqrt{im + \color{blue}{im}} \cdot \frac{1}{2} \]
      6. lower-+.f6451.5%

        \[\leadsto \sqrt{im + \color{blue}{im}} \cdot \frac{1}{2} \]
    6. Applied rewrites51.5%

      \[\leadsto \color{blue}{\sqrt{im + im} \cdot \frac{1}{2}} \]
    7. Taylor expanded in undef-var around zero

      \[\leadsto \sqrt{im + im} \cdot \color{blue}{0} \]
    8. Step-by-step derivation
      1. Applied rewrites6.0%

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

      if 5.3999999999999997e-229 < im

      1. Initial program 41.8%

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

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

          \[\leadsto \frac{1}{2} \cdot \sqrt{2 \cdot \color{blue}{im}} \]
      4. Applied rewrites51.5%

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

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

          \[\leadsto \color{blue}{\sqrt{2 \cdot im} \cdot \frac{1}{2}} \]
        3. lower-*.f6451.5%

          \[\leadsto \color{blue}{\sqrt{2 \cdot im} \cdot \frac{1}{2}} \]
        4. lift-*.f64N/A

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

          \[\leadsto \sqrt{im + \color{blue}{im}} \cdot \frac{1}{2} \]
        6. lower-+.f6451.5%

          \[\leadsto \sqrt{im + \color{blue}{im}} \cdot \frac{1}{2} \]
      6. Applied rewrites51.5%

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

    Alternative 8: 51.5% accurate, 2.5× speedup?

    \[\sqrt{im + im} \cdot \frac{1}{2} \]
    (FPCore (re im)
      :precision binary64
      (* (sqrt (+ im im)) 1/2))
    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] * 1/2), $MachinePrecision]
    
    \sqrt{im + im} \cdot \frac{1}{2}
    
    Derivation
    1. Initial program 41.8%

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

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

        \[\leadsto \frac{1}{2} \cdot \sqrt{2 \cdot \color{blue}{im}} \]
    4. Applied rewrites51.5%

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

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

        \[\leadsto \color{blue}{\sqrt{2 \cdot im} \cdot \frac{1}{2}} \]
      3. lower-*.f6451.5%

        \[\leadsto \color{blue}{\sqrt{2 \cdot im} \cdot \frac{1}{2}} \]
      4. lift-*.f64N/A

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

        \[\leadsto \sqrt{im + \color{blue}{im}} \cdot \frac{1}{2} \]
      6. lower-+.f6451.5%

        \[\leadsto \sqrt{im + \color{blue}{im}} \cdot \frac{1}{2} \]
    6. Applied rewrites51.5%

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

    Reproduce

    ?
    herbie shell --seed 2025274 -o generate:evaluate
    (FPCore (re im)
      :name "math.sqrt on complex, imaginary part, im greater than 0 branch"
      :precision binary64
      :pre (> im 0)
      (* 1/2 (sqrt (* 2 (- (sqrt (+ (* re re) (* im im))) re)))))