1/2(abs(p)+abs(r) - sqrt((p-r)^2 + 4q^2))

Percentage Accurate: 24.3% → 57.3%
Time: 9.0s
Alternatives: 8
Speedup: 83.3×

Specification

?
\[\begin{array}{l} \\ \frac{1}{2} \cdot \left(\left(\left|p\right| + \left|r\right|\right) - \sqrt{{\left(p - r\right)}^{2} + 4 \cdot {q}^{2}}\right) \end{array} \]
(FPCore (p r q)
 :precision binary64
 (*
  (/ 1.0 2.0)
  (- (+ (fabs p) (fabs r)) (sqrt (+ (pow (- p r) 2.0) (* 4.0 (pow q 2.0)))))))
double code(double p, double r, double q) {
	return (1.0 / 2.0) * ((fabs(p) + fabs(r)) - sqrt((pow((p - r), 2.0) + (4.0 * pow(q, 2.0)))));
}
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(p, r, q)
use fmin_fmax_functions
    real(8), intent (in) :: p
    real(8), intent (in) :: r
    real(8), intent (in) :: q
    code = (1.0d0 / 2.0d0) * ((abs(p) + abs(r)) - sqrt((((p - r) ** 2.0d0) + (4.0d0 * (q ** 2.0d0)))))
end function
public static double code(double p, double r, double q) {
	return (1.0 / 2.0) * ((Math.abs(p) + Math.abs(r)) - Math.sqrt((Math.pow((p - r), 2.0) + (4.0 * Math.pow(q, 2.0)))));
}
def code(p, r, q):
	return (1.0 / 2.0) * ((math.fabs(p) + math.fabs(r)) - math.sqrt((math.pow((p - r), 2.0) + (4.0 * math.pow(q, 2.0)))))
function code(p, r, q)
	return Float64(Float64(1.0 / 2.0) * Float64(Float64(abs(p) + abs(r)) - sqrt(Float64((Float64(p - r) ^ 2.0) + Float64(4.0 * (q ^ 2.0))))))
end
function tmp = code(p, r, q)
	tmp = (1.0 / 2.0) * ((abs(p) + abs(r)) - sqrt((((p - r) ^ 2.0) + (4.0 * (q ^ 2.0)))));
end
code[p_, r_, q_] := N[(N[(1.0 / 2.0), $MachinePrecision] * N[(N[(N[Abs[p], $MachinePrecision] + N[Abs[r], $MachinePrecision]), $MachinePrecision] - N[Sqrt[N[(N[Power[N[(p - r), $MachinePrecision], 2.0], $MachinePrecision] + N[(4.0 * N[Power[q, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{1}{2} \cdot \left(\left(\left|p\right| + \left|r\right|\right) - \sqrt{{\left(p - r\right)}^{2} + 4 \cdot {q}^{2}}\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 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: 24.3% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \frac{1}{2} \cdot \left(\left(\left|p\right| + \left|r\right|\right) - \sqrt{{\left(p - r\right)}^{2} + 4 \cdot {q}^{2}}\right) \end{array} \]
(FPCore (p r q)
 :precision binary64
 (*
  (/ 1.0 2.0)
  (- (+ (fabs p) (fabs r)) (sqrt (+ (pow (- p r) 2.0) (* 4.0 (pow q 2.0)))))))
double code(double p, double r, double q) {
	return (1.0 / 2.0) * ((fabs(p) + fabs(r)) - sqrt((pow((p - r), 2.0) + (4.0 * pow(q, 2.0)))));
}
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(p, r, q)
use fmin_fmax_functions
    real(8), intent (in) :: p
    real(8), intent (in) :: r
    real(8), intent (in) :: q
    code = (1.0d0 / 2.0d0) * ((abs(p) + abs(r)) - sqrt((((p - r) ** 2.0d0) + (4.0d0 * (q ** 2.0d0)))))
end function
public static double code(double p, double r, double q) {
	return (1.0 / 2.0) * ((Math.abs(p) + Math.abs(r)) - Math.sqrt((Math.pow((p - r), 2.0) + (4.0 * Math.pow(q, 2.0)))));
}
def code(p, r, q):
	return (1.0 / 2.0) * ((math.fabs(p) + math.fabs(r)) - math.sqrt((math.pow((p - r), 2.0) + (4.0 * math.pow(q, 2.0)))))
function code(p, r, q)
	return Float64(Float64(1.0 / 2.0) * Float64(Float64(abs(p) + abs(r)) - sqrt(Float64((Float64(p - r) ^ 2.0) + Float64(4.0 * (q ^ 2.0))))))
end
function tmp = code(p, r, q)
	tmp = (1.0 / 2.0) * ((abs(p) + abs(r)) - sqrt((((p - r) ^ 2.0) + (4.0 * (q ^ 2.0)))));
end
code[p_, r_, q_] := N[(N[(1.0 / 2.0), $MachinePrecision] * N[(N[(N[Abs[p], $MachinePrecision] + N[Abs[r], $MachinePrecision]), $MachinePrecision] - N[Sqrt[N[(N[Power[N[(p - r), $MachinePrecision], 2.0], $MachinePrecision] + N[(4.0 * N[Power[q, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{1}{2} \cdot \left(\left(\left|p\right| + \left|r\right|\right) - \sqrt{{\left(p - r\right)}^{2} + 4 \cdot {q}^{2}}\right)
\end{array}

Alternative 1: 57.3% accurate, 14.7× speedup?

\[\begin{array}{l} q_m = \left|q\right| \\ [p, r, q_m] = \mathsf{sort}([p, r, q_m])\\ \\ \begin{array}{l} \mathbf{if}\;q\_m \leq 1.75 \cdot 10^{-16}:\\ \;\;\;\;-0.5 \cdot \left(r - \left|r\right|\right)\\ \mathbf{else}:\\ \;\;\;\;-q\_m\\ \end{array} \end{array} \]
q_m = (fabs.f64 q)
NOTE: p, r, and q_m should be sorted in increasing order before calling this function.
(FPCore (p r q_m)
 :precision binary64
 (if (<= q_m 1.75e-16) (* -0.5 (- r (fabs r))) (- q_m)))
q_m = fabs(q);
assert(p < r && r < q_m);
double code(double p, double r, double q_m) {
	double tmp;
	if (q_m <= 1.75e-16) {
		tmp = -0.5 * (r - fabs(r));
	} else {
		tmp = -q_m;
	}
	return tmp;
}
q_m =     private
NOTE: p, r, and q_m should be sorted in increasing order before calling this function.
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(p, r, q_m)
use fmin_fmax_functions
    real(8), intent (in) :: p
    real(8), intent (in) :: r
    real(8), intent (in) :: q_m
    real(8) :: tmp
    if (q_m <= 1.75d-16) then
        tmp = (-0.5d0) * (r - abs(r))
    else
        tmp = -q_m
    end if
    code = tmp
end function
q_m = Math.abs(q);
assert p < r && r < q_m;
public static double code(double p, double r, double q_m) {
	double tmp;
	if (q_m <= 1.75e-16) {
		tmp = -0.5 * (r - Math.abs(r));
	} else {
		tmp = -q_m;
	}
	return tmp;
}
q_m = math.fabs(q)
[p, r, q_m] = sort([p, r, q_m])
def code(p, r, q_m):
	tmp = 0
	if q_m <= 1.75e-16:
		tmp = -0.5 * (r - math.fabs(r))
	else:
		tmp = -q_m
	return tmp
q_m = abs(q)
p, r, q_m = sort([p, r, q_m])
function code(p, r, q_m)
	tmp = 0.0
	if (q_m <= 1.75e-16)
		tmp = Float64(-0.5 * Float64(r - abs(r)));
	else
		tmp = Float64(-q_m);
	end
	return tmp
end
q_m = abs(q);
p, r, q_m = num2cell(sort([p, r, q_m])){:}
function tmp_2 = code(p, r, q_m)
	tmp = 0.0;
	if (q_m <= 1.75e-16)
		tmp = -0.5 * (r - abs(r));
	else
		tmp = -q_m;
	end
	tmp_2 = tmp;
end
q_m = N[Abs[q], $MachinePrecision]
NOTE: p, r, and q_m should be sorted in increasing order before calling this function.
code[p_, r_, q$95$m_] := If[LessEqual[q$95$m, 1.75e-16], N[(-0.5 * N[(r - N[Abs[r], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], (-q$95$m)]
\begin{array}{l}
q_m = \left|q\right|
\\
[p, r, q_m] = \mathsf{sort}([p, r, q_m])\\
\\
\begin{array}{l}
\mathbf{if}\;q\_m \leq 1.75 \cdot 10^{-16}:\\
\;\;\;\;-0.5 \cdot \left(r - \left|r\right|\right)\\

\mathbf{else}:\\
\;\;\;\;-q\_m\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if q < 1.75000000000000009e-16

    1. Initial program 22.1%

      \[\frac{1}{2} \cdot \left(\left(\left|p\right| + \left|r\right|\right) - \sqrt{{\left(p - r\right)}^{2} + 4 \cdot {q}^{2}}\right) \]
    2. Add Preprocessing
    3. Taylor expanded in r around inf

      \[\leadsto \color{blue}{r \cdot \left(\frac{1}{2} \cdot \frac{\left(\left|p\right| + \left|r\right|\right) - -1 \cdot p}{r} - \frac{1}{2}\right)} \]
    4. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \color{blue}{\left(\frac{1}{2} \cdot \frac{\left(\left|p\right| + \left|r\right|\right) - -1 \cdot p}{r} - \frac{1}{2}\right) \cdot r} \]
      2. lower-*.f64N/A

        \[\leadsto \color{blue}{\left(\frac{1}{2} \cdot \frac{\left(\left|p\right| + \left|r\right|\right) - -1 \cdot p}{r} - \frac{1}{2}\right) \cdot r} \]
    5. Applied rewrites9.6%

      \[\leadsto \color{blue}{\left(\frac{\left(\left|r\right| + p\right) + \left|p\right|}{r} \cdot 0.5 - 0.5\right) \cdot r} \]
    6. Taylor expanded in r around 0

      \[\leadsto \frac{-1}{2} \cdot r + \color{blue}{\frac{1}{2} \cdot \left(p + \left(\left|p\right| + \left|r\right|\right)\right)} \]
    7. Step-by-step derivation
      1. Applied rewrites9.6%

        \[\leadsto -0.5 \cdot \color{blue}{\left(r - \left(\left(p + \left|r\right|\right) + \left|p\right|\right)\right)} \]
      2. Step-by-step derivation
        1. Applied rewrites6.8%

          \[\leadsto -0.5 \cdot \left(r - \mathsf{fma}\left(\sqrt{-p}, \sqrt{-p}, \left|r\right| + p\right)\right) \]
        2. Taylor expanded in p around 0

          \[\leadsto \frac{-1}{2} \cdot \left(r - \left|r\right|\right) \]
        3. Step-by-step derivation
          1. Applied rewrites21.0%

            \[\leadsto -0.5 \cdot \left(r - \left|r\right|\right) \]

          if 1.75000000000000009e-16 < q

          1. Initial program 21.9%

            \[\frac{1}{2} \cdot \left(\left(\left|p\right| + \left|r\right|\right) - \sqrt{{\left(p - r\right)}^{2} + 4 \cdot {q}^{2}}\right) \]
          2. Add Preprocessing
          3. Taylor expanded in q around inf

            \[\leadsto \color{blue}{-1 \cdot q} \]
          4. Step-by-step derivation
            1. mul-1-negN/A

              \[\leadsto \color{blue}{\mathsf{neg}\left(q\right)} \]
            2. lower-neg.f6451.3

              \[\leadsto \color{blue}{-q} \]
          5. Applied rewrites51.3%

            \[\leadsto \color{blue}{-q} \]
        4. Recombined 2 regimes into one program.
        5. Add Preprocessing

        Alternative 2: 34.4% accurate, 1.6× speedup?

        \[\begin{array}{l} q_m = \left|q\right| \\ [p, r, q_m] = \mathsf{sort}([p, r, q_m])\\ \\ \begin{array}{l} \mathbf{if}\;q\_m \leq 1.65 \cdot 10^{-59}:\\ \;\;\;\;\left(\left(r - \left|r\right|\right) - \left(\left|p\right| - p\right)\right) \cdot -0.5\\ \mathbf{elif}\;q\_m \leq 5.5 \cdot 10^{+83}:\\ \;\;\;\;{2}^{-1} \cdot \frac{\mathsf{fma}\left(\left(p + \left(\left|r\right| - r\right)\right) + \left|p\right|, r, -2 \cdot \left(q\_m \cdot q\_m\right)\right)}{r}\\ \mathbf{else}:\\ \;\;\;\;-q\_m\\ \end{array} \end{array} \]
        q_m = (fabs.f64 q)
        NOTE: p, r, and q_m should be sorted in increasing order before calling this function.
        (FPCore (p r q_m)
         :precision binary64
         (if (<= q_m 1.65e-59)
           (* (- (- r (fabs r)) (- (fabs p) p)) -0.5)
           (if (<= q_m 5.5e+83)
             (*
              (pow 2.0 -1.0)
              (/ (fma (+ (+ p (- (fabs r) r)) (fabs p)) r (* -2.0 (* q_m q_m))) r))
             (- q_m))))
        q_m = fabs(q);
        assert(p < r && r < q_m);
        double code(double p, double r, double q_m) {
        	double tmp;
        	if (q_m <= 1.65e-59) {
        		tmp = ((r - fabs(r)) - (fabs(p) - p)) * -0.5;
        	} else if (q_m <= 5.5e+83) {
        		tmp = pow(2.0, -1.0) * (fma(((p + (fabs(r) - r)) + fabs(p)), r, (-2.0 * (q_m * q_m))) / r);
        	} else {
        		tmp = -q_m;
        	}
        	return tmp;
        }
        
        q_m = abs(q)
        p, r, q_m = sort([p, r, q_m])
        function code(p, r, q_m)
        	tmp = 0.0
        	if (q_m <= 1.65e-59)
        		tmp = Float64(Float64(Float64(r - abs(r)) - Float64(abs(p) - p)) * -0.5);
        	elseif (q_m <= 5.5e+83)
        		tmp = Float64((2.0 ^ -1.0) * Float64(fma(Float64(Float64(p + Float64(abs(r) - r)) + abs(p)), r, Float64(-2.0 * Float64(q_m * q_m))) / r));
        	else
        		tmp = Float64(-q_m);
        	end
        	return tmp
        end
        
        q_m = N[Abs[q], $MachinePrecision]
        NOTE: p, r, and q_m should be sorted in increasing order before calling this function.
        code[p_, r_, q$95$m_] := If[LessEqual[q$95$m, 1.65e-59], N[(N[(N[(r - N[Abs[r], $MachinePrecision]), $MachinePrecision] - N[(N[Abs[p], $MachinePrecision] - p), $MachinePrecision]), $MachinePrecision] * -0.5), $MachinePrecision], If[LessEqual[q$95$m, 5.5e+83], N[(N[Power[2.0, -1.0], $MachinePrecision] * N[(N[(N[(N[(p + N[(N[Abs[r], $MachinePrecision] - r), $MachinePrecision]), $MachinePrecision] + N[Abs[p], $MachinePrecision]), $MachinePrecision] * r + N[(-2.0 * N[(q$95$m * q$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / r), $MachinePrecision]), $MachinePrecision], (-q$95$m)]]
        
        \begin{array}{l}
        q_m = \left|q\right|
        \\
        [p, r, q_m] = \mathsf{sort}([p, r, q_m])\\
        \\
        \begin{array}{l}
        \mathbf{if}\;q\_m \leq 1.65 \cdot 10^{-59}:\\
        \;\;\;\;\left(\left(r - \left|r\right|\right) - \left(\left|p\right| - p\right)\right) \cdot -0.5\\
        
        \mathbf{elif}\;q\_m \leq 5.5 \cdot 10^{+83}:\\
        \;\;\;\;{2}^{-1} \cdot \frac{\mathsf{fma}\left(\left(p + \left(\left|r\right| - r\right)\right) + \left|p\right|, r, -2 \cdot \left(q\_m \cdot q\_m\right)\right)}{r}\\
        
        \mathbf{else}:\\
        \;\;\;\;-q\_m\\
        
        
        \end{array}
        \end{array}
        
        Derivation
        1. Split input into 3 regimes
        2. if q < 1.64999999999999991e-59

          1. Initial program 22.3%

            \[\frac{1}{2} \cdot \left(\left(\left|p\right| + \left|r\right|\right) - \sqrt{{\left(p - r\right)}^{2} + 4 \cdot {q}^{2}}\right) \]
          2. Add Preprocessing
          3. Taylor expanded in r around inf

            \[\leadsto \color{blue}{r \cdot \left(\frac{1}{2} \cdot \frac{\left(\left|p\right| + \left|r\right|\right) - -1 \cdot p}{r} - \frac{1}{2}\right)} \]
          4. Step-by-step derivation
            1. *-commutativeN/A

              \[\leadsto \color{blue}{\left(\frac{1}{2} \cdot \frac{\left(\left|p\right| + \left|r\right|\right) - -1 \cdot p}{r} - \frac{1}{2}\right) \cdot r} \]
            2. lower-*.f64N/A

              \[\leadsto \color{blue}{\left(\frac{1}{2} \cdot \frac{\left(\left|p\right| + \left|r\right|\right) - -1 \cdot p}{r} - \frac{1}{2}\right) \cdot r} \]
          5. Applied rewrites10.0%

            \[\leadsto \color{blue}{\left(\frac{\left(\left|r\right| + p\right) + \left|p\right|}{r} \cdot 0.5 - 0.5\right) \cdot r} \]
          6. Taylor expanded in r around 0

            \[\leadsto \frac{-1}{2} \cdot r + \color{blue}{\frac{1}{2} \cdot \left(p + \left(\left|p\right| + \left|r\right|\right)\right)} \]
          7. Step-by-step derivation
            1. Applied rewrites10.0%

              \[\leadsto -0.5 \cdot \color{blue}{\left(r - \left(\left(p + \left|r\right|\right) + \left|p\right|\right)\right)} \]
            2. Step-by-step derivation
              1. Applied rewrites32.3%

                \[\leadsto \color{blue}{\left(\left(r - \left|r\right|\right) - \left(\left|p\right| + p\right)\right) \cdot -0.5} \]

              if 1.64999999999999991e-59 < q < 5.4999999999999996e83

              1. Initial program 18.9%

                \[\frac{1}{2} \cdot \left(\left(\left|p\right| + \left|r\right|\right) - \sqrt{{\left(p - r\right)}^{2} + 4 \cdot {q}^{2}}\right) \]
              2. Add Preprocessing
              3. Taylor expanded in r around inf

                \[\leadsto \frac{1}{2} \cdot \color{blue}{\left(r \cdot \left(\left(-2 \cdot \frac{{q}^{2}}{{r}^{2}} + \left(\frac{\left|p\right|}{r} + \frac{\left|r\right|}{r}\right)\right) - \left(1 + -1 \cdot \frac{p}{r}\right)\right)\right)} \]
              4. Step-by-step derivation
                1. *-commutativeN/A

                  \[\leadsto \frac{1}{2} \cdot \color{blue}{\left(\left(\left(-2 \cdot \frac{{q}^{2}}{{r}^{2}} + \left(\frac{\left|p\right|}{r} + \frac{\left|r\right|}{r}\right)\right) - \left(1 + -1 \cdot \frac{p}{r}\right)\right) \cdot r\right)} \]
                2. lower-*.f64N/A

                  \[\leadsto \frac{1}{2} \cdot \color{blue}{\left(\left(\left(-2 \cdot \frac{{q}^{2}}{{r}^{2}} + \left(\frac{\left|p\right|}{r} + \frac{\left|r\right|}{r}\right)\right) - \left(1 + -1 \cdot \frac{p}{r}\right)\right) \cdot r\right)} \]
              5. Applied rewrites16.5%

                \[\leadsto \frac{1}{2} \cdot \color{blue}{\left(\mathsf{fma}\left(\frac{-2}{r}, \frac{q \cdot q}{r}, \frac{\left(\left|r\right| + p\right) + \left|p\right|}{r} - 1\right) \cdot r\right)} \]
              6. Taylor expanded in r around 0

                \[\leadsto \frac{1}{2} \cdot \frac{-2 \cdot {q}^{2} + r \cdot \left(p + \left(\left|p\right| + \left(\left|r\right| + -1 \cdot r\right)\right)\right)}{\color{blue}{r}} \]
              7. Step-by-step derivation
                1. Applied rewrites24.2%

                  \[\leadsto \frac{1}{2} \cdot \frac{\mathsf{fma}\left(\left(p + \left(\left|r\right| - r\right)\right) + \left|p\right|, r, -2 \cdot \left(q \cdot q\right)\right)}{\color{blue}{r}} \]

                if 5.4999999999999996e83 < q

                1. Initial program 23.8%

                  \[\frac{1}{2} \cdot \left(\left(\left|p\right| + \left|r\right|\right) - \sqrt{{\left(p - r\right)}^{2} + 4 \cdot {q}^{2}}\right) \]
                2. Add Preprocessing
                3. Taylor expanded in q around inf

                  \[\leadsto \color{blue}{-1 \cdot q} \]
                4. Step-by-step derivation
                  1. mul-1-negN/A

                    \[\leadsto \color{blue}{\mathsf{neg}\left(q\right)} \]
                  2. lower-neg.f6468.8

                    \[\leadsto \color{blue}{-q} \]
                5. Applied rewrites68.8%

                  \[\leadsto \color{blue}{-q} \]
              8. Recombined 3 regimes into one program.
              9. Final simplification16.8%

                \[\leadsto \begin{array}{l} \mathbf{if}\;q \leq 1.65 \cdot 10^{-59}:\\ \;\;\;\;\left(\left(r - \left|r\right|\right) - \left(\left|p\right| - p\right)\right) \cdot -0.5\\ \mathbf{elif}\;q \leq 5.5 \cdot 10^{+83}:\\ \;\;\;\;{2}^{-1} \cdot \frac{\mathsf{fma}\left(\left(p + \left(\left|r\right| - r\right)\right) + \left|p\right|, r, -2 \cdot \left(q \cdot q\right)\right)}{r}\\ \mathbf{else}:\\ \;\;\;\;-q\\ \end{array} \]
              10. Add Preprocessing

              Alternative 3: 30.3% accurate, 1.7× speedup?

              \[\begin{array}{l} q_m = \left|q\right| \\ [p, r, q_m] = \mathsf{sort}([p, r, q_m])\\ \\ \begin{array}{l} \mathbf{if}\;q\_m \leq 5.5 \cdot 10^{-16}:\\ \;\;\;\;\left(\left(r - \left|r\right|\right) - \left(\left|p\right| - p\right)\right) \cdot -0.5\\ \mathbf{elif}\;q\_m \leq 4.7 \cdot 10^{+25} \lor \neg \left(q\_m \leq 2.05 \cdot 10^{+82}\right):\\ \;\;\;\;-q\_m\\ \mathbf{else}:\\ \;\;\;\;{2}^{-1} \cdot \left(-2 \cdot \mathsf{fma}\left(q\_m, \frac{q\_m}{r}, p\right)\right)\\ \end{array} \end{array} \]
              q_m = (fabs.f64 q)
              NOTE: p, r, and q_m should be sorted in increasing order before calling this function.
              (FPCore (p r q_m)
               :precision binary64
               (if (<= q_m 5.5e-16)
                 (* (- (- r (fabs r)) (- (fabs p) p)) -0.5)
                 (if (or (<= q_m 4.7e+25) (not (<= q_m 2.05e+82)))
                   (- q_m)
                   (* (pow 2.0 -1.0) (* -2.0 (fma q_m (/ q_m r) p))))))
              q_m = fabs(q);
              assert(p < r && r < q_m);
              double code(double p, double r, double q_m) {
              	double tmp;
              	if (q_m <= 5.5e-16) {
              		tmp = ((r - fabs(r)) - (fabs(p) - p)) * -0.5;
              	} else if ((q_m <= 4.7e+25) || !(q_m <= 2.05e+82)) {
              		tmp = -q_m;
              	} else {
              		tmp = pow(2.0, -1.0) * (-2.0 * fma(q_m, (q_m / r), p));
              	}
              	return tmp;
              }
              
              q_m = abs(q)
              p, r, q_m = sort([p, r, q_m])
              function code(p, r, q_m)
              	tmp = 0.0
              	if (q_m <= 5.5e-16)
              		tmp = Float64(Float64(Float64(r - abs(r)) - Float64(abs(p) - p)) * -0.5);
              	elseif ((q_m <= 4.7e+25) || !(q_m <= 2.05e+82))
              		tmp = Float64(-q_m);
              	else
              		tmp = Float64((2.0 ^ -1.0) * Float64(-2.0 * fma(q_m, Float64(q_m / r), p)));
              	end
              	return tmp
              end
              
              q_m = N[Abs[q], $MachinePrecision]
              NOTE: p, r, and q_m should be sorted in increasing order before calling this function.
              code[p_, r_, q$95$m_] := If[LessEqual[q$95$m, 5.5e-16], N[(N[(N[(r - N[Abs[r], $MachinePrecision]), $MachinePrecision] - N[(N[Abs[p], $MachinePrecision] - p), $MachinePrecision]), $MachinePrecision] * -0.5), $MachinePrecision], If[Or[LessEqual[q$95$m, 4.7e+25], N[Not[LessEqual[q$95$m, 2.05e+82]], $MachinePrecision]], (-q$95$m), N[(N[Power[2.0, -1.0], $MachinePrecision] * N[(-2.0 * N[(q$95$m * N[(q$95$m / r), $MachinePrecision] + p), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
              
              \begin{array}{l}
              q_m = \left|q\right|
              \\
              [p, r, q_m] = \mathsf{sort}([p, r, q_m])\\
              \\
              \begin{array}{l}
              \mathbf{if}\;q\_m \leq 5.5 \cdot 10^{-16}:\\
              \;\;\;\;\left(\left(r - \left|r\right|\right) - \left(\left|p\right| - p\right)\right) \cdot -0.5\\
              
              \mathbf{elif}\;q\_m \leq 4.7 \cdot 10^{+25} \lor \neg \left(q\_m \leq 2.05 \cdot 10^{+82}\right):\\
              \;\;\;\;-q\_m\\
              
              \mathbf{else}:\\
              \;\;\;\;{2}^{-1} \cdot \left(-2 \cdot \mathsf{fma}\left(q\_m, \frac{q\_m}{r}, p\right)\right)\\
              
              
              \end{array}
              \end{array}
              
              Derivation
              1. Split input into 3 regimes
              2. if q < 5.49999999999999964e-16

                1. Initial program 22.1%

                  \[\frac{1}{2} \cdot \left(\left(\left|p\right| + \left|r\right|\right) - \sqrt{{\left(p - r\right)}^{2} + 4 \cdot {q}^{2}}\right) \]
                2. Add Preprocessing
                3. Taylor expanded in r around inf

                  \[\leadsto \color{blue}{r \cdot \left(\frac{1}{2} \cdot \frac{\left(\left|p\right| + \left|r\right|\right) - -1 \cdot p}{r} - \frac{1}{2}\right)} \]
                4. Step-by-step derivation
                  1. *-commutativeN/A

                    \[\leadsto \color{blue}{\left(\frac{1}{2} \cdot \frac{\left(\left|p\right| + \left|r\right|\right) - -1 \cdot p}{r} - \frac{1}{2}\right) \cdot r} \]
                  2. lower-*.f64N/A

                    \[\leadsto \color{blue}{\left(\frac{1}{2} \cdot \frac{\left(\left|p\right| + \left|r\right|\right) - -1 \cdot p}{r} - \frac{1}{2}\right) \cdot r} \]
                5. Applied rewrites9.6%

                  \[\leadsto \color{blue}{\left(\frac{\left(\left|r\right| + p\right) + \left|p\right|}{r} \cdot 0.5 - 0.5\right) \cdot r} \]
                6. Taylor expanded in r around 0

                  \[\leadsto \frac{-1}{2} \cdot r + \color{blue}{\frac{1}{2} \cdot \left(p + \left(\left|p\right| + \left|r\right|\right)\right)} \]
                7. Step-by-step derivation
                  1. Applied rewrites9.6%

                    \[\leadsto -0.5 \cdot \color{blue}{\left(r - \left(\left(p + \left|r\right|\right) + \left|p\right|\right)\right)} \]
                  2. Step-by-step derivation
                    1. Applied rewrites31.4%

                      \[\leadsto \color{blue}{\left(\left(r - \left|r\right|\right) - \left(\left|p\right| + p\right)\right) \cdot -0.5} \]

                    if 5.49999999999999964e-16 < q < 4.6999999999999998e25 or 2.04999999999999998e82 < q

                    1. Initial program 22.8%

                      \[\frac{1}{2} \cdot \left(\left(\left|p\right| + \left|r\right|\right) - \sqrt{{\left(p - r\right)}^{2} + 4 \cdot {q}^{2}}\right) \]
                    2. Add Preprocessing
                    3. Taylor expanded in q around inf

                      \[\leadsto \color{blue}{-1 \cdot q} \]
                    4. Step-by-step derivation
                      1. mul-1-negN/A

                        \[\leadsto \color{blue}{\mathsf{neg}\left(q\right)} \]
                      2. lower-neg.f6458.3

                        \[\leadsto \color{blue}{-q} \]
                    5. Applied rewrites58.3%

                      \[\leadsto \color{blue}{-q} \]

                    if 4.6999999999999998e25 < q < 2.04999999999999998e82

                    1. Initial program 18.2%

                      \[\frac{1}{2} \cdot \left(\left(\left|p\right| + \left|r\right|\right) - \sqrt{{\left(p - r\right)}^{2} + 4 \cdot {q}^{2}}\right) \]
                    2. Add Preprocessing
                    3. Taylor expanded in r around inf

                      \[\leadsto \frac{1}{2} \cdot \color{blue}{\left(r \cdot \left(\left(-2 \cdot \frac{{q}^{2}}{{r}^{2}} + \left(\frac{\left|p\right|}{r} + \frac{\left|r\right|}{r}\right)\right) - \left(1 + -1 \cdot \frac{p}{r}\right)\right)\right)} \]
                    4. Step-by-step derivation
                      1. *-commutativeN/A

                        \[\leadsto \frac{1}{2} \cdot \color{blue}{\left(\left(\left(-2 \cdot \frac{{q}^{2}}{{r}^{2}} + \left(\frac{\left|p\right|}{r} + \frac{\left|r\right|}{r}\right)\right) - \left(1 + -1 \cdot \frac{p}{r}\right)\right) \cdot r\right)} \]
                      2. lower-*.f64N/A

                        \[\leadsto \frac{1}{2} \cdot \color{blue}{\left(\left(\left(-2 \cdot \frac{{q}^{2}}{{r}^{2}} + \left(\frac{\left|p\right|}{r} + \frac{\left|r\right|}{r}\right)\right) - \left(1 + -1 \cdot \frac{p}{r}\right)\right) \cdot r\right)} \]
                    5. Applied rewrites18.3%

                      \[\leadsto \frac{1}{2} \cdot \color{blue}{\left(\mathsf{fma}\left(\frac{-2}{r}, \frac{q \cdot q}{r}, \frac{\left(\left|r\right| + p\right) + \left|p\right|}{r} - 1\right) \cdot r\right)} \]
                    6. Step-by-step derivation
                      1. Applied rewrites2.5%

                        \[\leadsto \frac{1}{2} \cdot \left(\left(\frac{\mathsf{fma}\left(2, p, r\right)}{r} - \left(1 - \frac{-2 \cdot q}{r} \cdot \frac{q}{r}\right)\right) \cdot r\right) \]
                      2. Taylor expanded in p around inf

                        \[\leadsto \frac{1}{2} \cdot \left(\left(p \cdot \left(-2 \cdot \frac{{q}^{2}}{p \cdot {r}^{2}} + 2 \cdot \frac{1}{r}\right)\right) \cdot r\right) \]
                      3. Step-by-step derivation
                        1. Applied rewrites26.3%

                          \[\leadsto \frac{1}{2} \cdot \left(\left(\mathsf{fma}\left(\frac{\frac{\frac{q \cdot q}{r}}{p}}{r}, -2, \frac{2}{r}\right) \cdot p\right) \cdot r\right) \]
                        2. Taylor expanded in p around 0

                          \[\leadsto \frac{1}{2} \cdot \left(-2 \cdot \frac{{q}^{2}}{r} + \color{blue}{2 \cdot p}\right) \]
                        3. Step-by-step derivation
                          1. Applied rewrites26.5%

                            \[\leadsto \frac{1}{2} \cdot \left(-2 \cdot \color{blue}{\mathsf{fma}\left(q, \frac{q}{r}, -p\right)}\right) \]
                        4. Recombined 3 regimes into one program.
                        5. Final simplification15.8%

                          \[\leadsto \begin{array}{l} \mathbf{if}\;q \leq 5.5 \cdot 10^{-16}:\\ \;\;\;\;\left(\left(r - \left|r\right|\right) - \left(\left|p\right| - p\right)\right) \cdot -0.5\\ \mathbf{elif}\;q \leq 4.7 \cdot 10^{+25} \lor \neg \left(q \leq 2.05 \cdot 10^{+82}\right):\\ \;\;\;\;-q\\ \mathbf{else}:\\ \;\;\;\;{2}^{-1} \cdot \left(-2 \cdot \mathsf{fma}\left(q, \frac{q}{r}, p\right)\right)\\ \end{array} \]
                        6. Add Preprocessing

                        Alternative 4: 48.8% accurate, 2.2× speedup?

                        \[\begin{array}{l} q_m = \left|q\right| \\ [p, r, q_m] = \mathsf{sort}([p, r, q_m])\\ \\ \begin{array}{l} \mathbf{if}\;4 \cdot {q\_m}^{2} \leq 5 \cdot 10^{-111}:\\ \;\;\;\;0\\ \mathbf{else}:\\ \;\;\;\;-q\_m\\ \end{array} \end{array} \]
                        q_m = (fabs.f64 q)
                        NOTE: p, r, and q_m should be sorted in increasing order before calling this function.
                        (FPCore (p r q_m)
                         :precision binary64
                         (if (<= (* 4.0 (pow q_m 2.0)) 5e-111) 0.0 (- q_m)))
                        q_m = fabs(q);
                        assert(p < r && r < q_m);
                        double code(double p, double r, double q_m) {
                        	double tmp;
                        	if ((4.0 * pow(q_m, 2.0)) <= 5e-111) {
                        		tmp = 0.0;
                        	} else {
                        		tmp = -q_m;
                        	}
                        	return tmp;
                        }
                        
                        q_m =     private
                        NOTE: p, r, and q_m should be sorted in increasing order before calling this function.
                        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(p, r, q_m)
                        use fmin_fmax_functions
                            real(8), intent (in) :: p
                            real(8), intent (in) :: r
                            real(8), intent (in) :: q_m
                            real(8) :: tmp
                            if ((4.0d0 * (q_m ** 2.0d0)) <= 5d-111) then
                                tmp = 0.0d0
                            else
                                tmp = -q_m
                            end if
                            code = tmp
                        end function
                        
                        q_m = Math.abs(q);
                        assert p < r && r < q_m;
                        public static double code(double p, double r, double q_m) {
                        	double tmp;
                        	if ((4.0 * Math.pow(q_m, 2.0)) <= 5e-111) {
                        		tmp = 0.0;
                        	} else {
                        		tmp = -q_m;
                        	}
                        	return tmp;
                        }
                        
                        q_m = math.fabs(q)
                        [p, r, q_m] = sort([p, r, q_m])
                        def code(p, r, q_m):
                        	tmp = 0
                        	if (4.0 * math.pow(q_m, 2.0)) <= 5e-111:
                        		tmp = 0.0
                        	else:
                        		tmp = -q_m
                        	return tmp
                        
                        q_m = abs(q)
                        p, r, q_m = sort([p, r, q_m])
                        function code(p, r, q_m)
                        	tmp = 0.0
                        	if (Float64(4.0 * (q_m ^ 2.0)) <= 5e-111)
                        		tmp = 0.0;
                        	else
                        		tmp = Float64(-q_m);
                        	end
                        	return tmp
                        end
                        
                        q_m = abs(q);
                        p, r, q_m = num2cell(sort([p, r, q_m])){:}
                        function tmp_2 = code(p, r, q_m)
                        	tmp = 0.0;
                        	if ((4.0 * (q_m ^ 2.0)) <= 5e-111)
                        		tmp = 0.0;
                        	else
                        		tmp = -q_m;
                        	end
                        	tmp_2 = tmp;
                        end
                        
                        q_m = N[Abs[q], $MachinePrecision]
                        NOTE: p, r, and q_m should be sorted in increasing order before calling this function.
                        code[p_, r_, q$95$m_] := If[LessEqual[N[(4.0 * N[Power[q$95$m, 2.0], $MachinePrecision]), $MachinePrecision], 5e-111], 0.0, (-q$95$m)]
                        
                        \begin{array}{l}
                        q_m = \left|q\right|
                        \\
                        [p, r, q_m] = \mathsf{sort}([p, r, q_m])\\
                        \\
                        \begin{array}{l}
                        \mathbf{if}\;4 \cdot {q\_m}^{2} \leq 5 \cdot 10^{-111}:\\
                        \;\;\;\;0\\
                        
                        \mathbf{else}:\\
                        \;\;\;\;-q\_m\\
                        
                        
                        \end{array}
                        \end{array}
                        
                        Derivation
                        1. Split input into 2 regimes
                        2. if (*.f64 #s(literal 4 binary64) (pow.f64 q #s(literal 2 binary64))) < 5.0000000000000003e-111

                          1. Initial program 19.7%

                            \[\frac{1}{2} \cdot \left(\left(\left|p\right| + \left|r\right|\right) - \sqrt{{\left(p - r\right)}^{2} + 4 \cdot {q}^{2}}\right) \]
                          2. Add Preprocessing
                          3. Taylor expanded in r around inf

                            \[\leadsto \color{blue}{r \cdot \left(\frac{1}{2} \cdot \frac{\left(\left|p\right| + \left|r\right|\right) - -1 \cdot p}{r} - \frac{1}{2}\right)} \]
                          4. Step-by-step derivation
                            1. *-commutativeN/A

                              \[\leadsto \color{blue}{\left(\frac{1}{2} \cdot \frac{\left(\left|p\right| + \left|r\right|\right) - -1 \cdot p}{r} - \frac{1}{2}\right) \cdot r} \]
                            2. lower-*.f64N/A

                              \[\leadsto \color{blue}{\left(\frac{1}{2} \cdot \frac{\left(\left|p\right| + \left|r\right|\right) - -1 \cdot p}{r} - \frac{1}{2}\right) \cdot r} \]
                          5. Applied rewrites16.0%

                            \[\leadsto \color{blue}{\left(\frac{\left(\left|r\right| + p\right) + \left|p\right|}{r} \cdot 0.5 - 0.5\right) \cdot r} \]
                          6. Taylor expanded in r around 0

                            \[\leadsto \frac{-1}{2} \cdot r + \color{blue}{\frac{1}{2} \cdot \left(p + \left(\left|p\right| + \left|r\right|\right)\right)} \]
                          7. Step-by-step derivation
                            1. Applied rewrites16.0%

                              \[\leadsto -0.5 \cdot \color{blue}{\left(r - \left(\left(p + \left|r\right|\right) + \left|p\right|\right)\right)} \]
                            2. Step-by-step derivation
                              1. Applied rewrites11.7%

                                \[\leadsto -0.5 \cdot \left(r - \mathsf{fma}\left(\sqrt{-p}, \sqrt{-p}, \left|r\right| + p\right)\right) \]
                              2. Taylor expanded in p around inf

                                \[\leadsto \frac{1}{2} \cdot \left(p \cdot \color{blue}{\left(1 + {\left(\sqrt{-1}\right)}^{2}\right)}\right) \]
                              3. Step-by-step derivation
                                1. Applied rewrites35.2%

                                  \[\leadsto 0 \cdot p \]

                                if 5.0000000000000003e-111 < (*.f64 #s(literal 4 binary64) (pow.f64 q #s(literal 2 binary64)))

                                1. Initial program 23.6%

                                  \[\frac{1}{2} \cdot \left(\left(\left|p\right| + \left|r\right|\right) - \sqrt{{\left(p - r\right)}^{2} + 4 \cdot {q}^{2}}\right) \]
                                2. Add Preprocessing
                                3. Taylor expanded in q around inf

                                  \[\leadsto \color{blue}{-1 \cdot q} \]
                                4. Step-by-step derivation
                                  1. mul-1-negN/A

                                    \[\leadsto \color{blue}{\mathsf{neg}\left(q\right)} \]
                                  2. lower-neg.f6424.0

                                    \[\leadsto \color{blue}{-q} \]
                                5. Applied rewrites24.0%

                                  \[\leadsto \color{blue}{-q} \]
                              4. Recombined 2 regimes into one program.
                              5. Final simplification28.4%

                                \[\leadsto \begin{array}{l} \mathbf{if}\;4 \cdot {q}^{2} \leq 5 \cdot 10^{-111}:\\ \;\;\;\;0\\ \mathbf{else}:\\ \;\;\;\;-q\\ \end{array} \]
                              6. Add Preprocessing

                              Alternative 5: 31.1% accurate, 5.2× speedup?

                              \[\begin{array}{l} q_m = \left|q\right| \\ [p, r, q_m] = \mathsf{sort}([p, r, q_m])\\ \\ \begin{array}{l} \mathbf{if}\;q\_m \leq 5.5 \cdot 10^{-16}:\\ \;\;\;\;\left(\left(r - \left|r\right|\right) - \left(\left|p\right| - p\right)\right) \cdot -0.5\\ \mathbf{elif}\;q\_m \leq 4.7 \cdot 10^{+25} \lor \neg \left(q\_m \leq 2.05 \cdot 10^{+82}\right):\\ \;\;\;\;-q\_m\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(p \cdot 2, 0.5, \frac{\left(-q\_m\right) \cdot q\_m}{r}\right)\\ \end{array} \end{array} \]
                              q_m = (fabs.f64 q)
                              NOTE: p, r, and q_m should be sorted in increasing order before calling this function.
                              (FPCore (p r q_m)
                               :precision binary64
                               (if (<= q_m 5.5e-16)
                                 (* (- (- r (fabs r)) (- (fabs p) p)) -0.5)
                                 (if (or (<= q_m 4.7e+25) (not (<= q_m 2.05e+82)))
                                   (- q_m)
                                   (fma (* p 2.0) 0.5 (/ (* (- q_m) q_m) r)))))
                              q_m = fabs(q);
                              assert(p < r && r < q_m);
                              double code(double p, double r, double q_m) {
                              	double tmp;
                              	if (q_m <= 5.5e-16) {
                              		tmp = ((r - fabs(r)) - (fabs(p) - p)) * -0.5;
                              	} else if ((q_m <= 4.7e+25) || !(q_m <= 2.05e+82)) {
                              		tmp = -q_m;
                              	} else {
                              		tmp = fma((p * 2.0), 0.5, ((-q_m * q_m) / r));
                              	}
                              	return tmp;
                              }
                              
                              q_m = abs(q)
                              p, r, q_m = sort([p, r, q_m])
                              function code(p, r, q_m)
                              	tmp = 0.0
                              	if (q_m <= 5.5e-16)
                              		tmp = Float64(Float64(Float64(r - abs(r)) - Float64(abs(p) - p)) * -0.5);
                              	elseif ((q_m <= 4.7e+25) || !(q_m <= 2.05e+82))
                              		tmp = Float64(-q_m);
                              	else
                              		tmp = fma(Float64(p * 2.0), 0.5, Float64(Float64(Float64(-q_m) * q_m) / r));
                              	end
                              	return tmp
                              end
                              
                              q_m = N[Abs[q], $MachinePrecision]
                              NOTE: p, r, and q_m should be sorted in increasing order before calling this function.
                              code[p_, r_, q$95$m_] := If[LessEqual[q$95$m, 5.5e-16], N[(N[(N[(r - N[Abs[r], $MachinePrecision]), $MachinePrecision] - N[(N[Abs[p], $MachinePrecision] - p), $MachinePrecision]), $MachinePrecision] * -0.5), $MachinePrecision], If[Or[LessEqual[q$95$m, 4.7e+25], N[Not[LessEqual[q$95$m, 2.05e+82]], $MachinePrecision]], (-q$95$m), N[(N[(p * 2.0), $MachinePrecision] * 0.5 + N[(N[((-q$95$m) * q$95$m), $MachinePrecision] / r), $MachinePrecision]), $MachinePrecision]]]
                              
                              \begin{array}{l}
                              q_m = \left|q\right|
                              \\
                              [p, r, q_m] = \mathsf{sort}([p, r, q_m])\\
                              \\
                              \begin{array}{l}
                              \mathbf{if}\;q\_m \leq 5.5 \cdot 10^{-16}:\\
                              \;\;\;\;\left(\left(r - \left|r\right|\right) - \left(\left|p\right| - p\right)\right) \cdot -0.5\\
                              
                              \mathbf{elif}\;q\_m \leq 4.7 \cdot 10^{+25} \lor \neg \left(q\_m \leq 2.05 \cdot 10^{+82}\right):\\
                              \;\;\;\;-q\_m\\
                              
                              \mathbf{else}:\\
                              \;\;\;\;\mathsf{fma}\left(p \cdot 2, 0.5, \frac{\left(-q\_m\right) \cdot q\_m}{r}\right)\\
                              
                              
                              \end{array}
                              \end{array}
                              
                              Derivation
                              1. Split input into 3 regimes
                              2. if q < 5.49999999999999964e-16

                                1. Initial program 22.1%

                                  \[\frac{1}{2} \cdot \left(\left(\left|p\right| + \left|r\right|\right) - \sqrt{{\left(p - r\right)}^{2} + 4 \cdot {q}^{2}}\right) \]
                                2. Add Preprocessing
                                3. Taylor expanded in r around inf

                                  \[\leadsto \color{blue}{r \cdot \left(\frac{1}{2} \cdot \frac{\left(\left|p\right| + \left|r\right|\right) - -1 \cdot p}{r} - \frac{1}{2}\right)} \]
                                4. Step-by-step derivation
                                  1. *-commutativeN/A

                                    \[\leadsto \color{blue}{\left(\frac{1}{2} \cdot \frac{\left(\left|p\right| + \left|r\right|\right) - -1 \cdot p}{r} - \frac{1}{2}\right) \cdot r} \]
                                  2. lower-*.f64N/A

                                    \[\leadsto \color{blue}{\left(\frac{1}{2} \cdot \frac{\left(\left|p\right| + \left|r\right|\right) - -1 \cdot p}{r} - \frac{1}{2}\right) \cdot r} \]
                                5. Applied rewrites9.6%

                                  \[\leadsto \color{blue}{\left(\frac{\left(\left|r\right| + p\right) + \left|p\right|}{r} \cdot 0.5 - 0.5\right) \cdot r} \]
                                6. Taylor expanded in r around 0

                                  \[\leadsto \frac{-1}{2} \cdot r + \color{blue}{\frac{1}{2} \cdot \left(p + \left(\left|p\right| + \left|r\right|\right)\right)} \]
                                7. Step-by-step derivation
                                  1. Applied rewrites9.6%

                                    \[\leadsto -0.5 \cdot \color{blue}{\left(r - \left(\left(p + \left|r\right|\right) + \left|p\right|\right)\right)} \]
                                  2. Step-by-step derivation
                                    1. Applied rewrites31.4%

                                      \[\leadsto \color{blue}{\left(\left(r - \left|r\right|\right) - \left(\left|p\right| + p\right)\right) \cdot -0.5} \]

                                    if 5.49999999999999964e-16 < q < 4.6999999999999998e25 or 2.04999999999999998e82 < q

                                    1. Initial program 22.8%

                                      \[\frac{1}{2} \cdot \left(\left(\left|p\right| + \left|r\right|\right) - \sqrt{{\left(p - r\right)}^{2} + 4 \cdot {q}^{2}}\right) \]
                                    2. Add Preprocessing
                                    3. Taylor expanded in q around inf

                                      \[\leadsto \color{blue}{-1 \cdot q} \]
                                    4. Step-by-step derivation
                                      1. mul-1-negN/A

                                        \[\leadsto \color{blue}{\mathsf{neg}\left(q\right)} \]
                                      2. lower-neg.f6458.3

                                        \[\leadsto \color{blue}{-q} \]
                                    5. Applied rewrites58.3%

                                      \[\leadsto \color{blue}{-q} \]

                                    if 4.6999999999999998e25 < q < 2.04999999999999998e82

                                    1. Initial program 18.2%

                                      \[\frac{1}{2} \cdot \left(\left(\left|p\right| + \left|r\right|\right) - \sqrt{{\left(p - r\right)}^{2} + 4 \cdot {q}^{2}}\right) \]
                                    2. Add Preprocessing
                                    3. Step-by-step derivation
                                      1. lift--.f64N/A

                                        \[\leadsto \frac{1}{2} \cdot \color{blue}{\left(\left(\left|p\right| + \left|r\right|\right) - \sqrt{{\left(p - r\right)}^{2} + 4 \cdot {q}^{2}}\right)} \]
                                      2. lift-+.f64N/A

                                        \[\leadsto \frac{1}{2} \cdot \left(\color{blue}{\left(\left|p\right| + \left|r\right|\right)} - \sqrt{{\left(p - r\right)}^{2} + 4 \cdot {q}^{2}}\right) \]
                                      3. associate--l+N/A

                                        \[\leadsto \frac{1}{2} \cdot \color{blue}{\left(\left|p\right| + \left(\left|r\right| - \sqrt{{\left(p - r\right)}^{2} + 4 \cdot {q}^{2}}\right)\right)} \]
                                      4. lift-fabs.f64N/A

                                        \[\leadsto \frac{1}{2} \cdot \left(\color{blue}{\left|p\right|} + \left(\left|r\right| - \sqrt{{\left(p - r\right)}^{2} + 4 \cdot {q}^{2}}\right)\right) \]
                                      5. rem-sqrt-square-revN/A

                                        \[\leadsto \frac{1}{2} \cdot \left(\color{blue}{\sqrt{p \cdot p}} + \left(\left|r\right| - \sqrt{{\left(p - r\right)}^{2} + 4 \cdot {q}^{2}}\right)\right) \]
                                      6. sqrt-prodN/A

                                        \[\leadsto \frac{1}{2} \cdot \left(\color{blue}{\sqrt{p} \cdot \sqrt{p}} + \left(\left|r\right| - \sqrt{{\left(p - r\right)}^{2} + 4 \cdot {q}^{2}}\right)\right) \]
                                      7. lower-fma.f64N/A

                                        \[\leadsto \frac{1}{2} \cdot \color{blue}{\mathsf{fma}\left(\sqrt{p}, \sqrt{p}, \left|r\right| - \sqrt{{\left(p - r\right)}^{2} + 4 \cdot {q}^{2}}\right)} \]
                                      8. rem-square-sqrtN/A

                                        \[\leadsto \frac{1}{2} \cdot \mathsf{fma}\left(\sqrt{\color{blue}{\sqrt{p} \cdot \sqrt{p}}}, \sqrt{p}, \left|r\right| - \sqrt{{\left(p - r\right)}^{2} + 4 \cdot {q}^{2}}\right) \]
                                      9. sqrt-prodN/A

                                        \[\leadsto \frac{1}{2} \cdot \mathsf{fma}\left(\sqrt{\color{blue}{\sqrt{p \cdot p}}}, \sqrt{p}, \left|r\right| - \sqrt{{\left(p - r\right)}^{2} + 4 \cdot {q}^{2}}\right) \]
                                      10. rem-sqrt-square-revN/A

                                        \[\leadsto \frac{1}{2} \cdot \mathsf{fma}\left(\sqrt{\color{blue}{\left|p\right|}}, \sqrt{p}, \left|r\right| - \sqrt{{\left(p - r\right)}^{2} + 4 \cdot {q}^{2}}\right) \]
                                      11. lift-fabs.f64N/A

                                        \[\leadsto \frac{1}{2} \cdot \mathsf{fma}\left(\sqrt{\color{blue}{\left|p\right|}}, \sqrt{p}, \left|r\right| - \sqrt{{\left(p - r\right)}^{2} + 4 \cdot {q}^{2}}\right) \]
                                      12. lower-sqrt.f64N/A

                                        \[\leadsto \frac{1}{2} \cdot \mathsf{fma}\left(\color{blue}{\sqrt{\left|p\right|}}, \sqrt{p}, \left|r\right| - \sqrt{{\left(p - r\right)}^{2} + 4 \cdot {q}^{2}}\right) \]
                                      13. lift-fabs.f64N/A

                                        \[\leadsto \frac{1}{2} \cdot \mathsf{fma}\left(\sqrt{\color{blue}{\left|p\right|}}, \sqrt{p}, \left|r\right| - \sqrt{{\left(p - r\right)}^{2} + 4 \cdot {q}^{2}}\right) \]
                                      14. rem-sqrt-square-revN/A

                                        \[\leadsto \frac{1}{2} \cdot \mathsf{fma}\left(\sqrt{\color{blue}{\sqrt{p \cdot p}}}, \sqrt{p}, \left|r\right| - \sqrt{{\left(p - r\right)}^{2} + 4 \cdot {q}^{2}}\right) \]
                                      15. sqrt-prodN/A

                                        \[\leadsto \frac{1}{2} \cdot \mathsf{fma}\left(\sqrt{\color{blue}{\sqrt{p} \cdot \sqrt{p}}}, \sqrt{p}, \left|r\right| - \sqrt{{\left(p - r\right)}^{2} + 4 \cdot {q}^{2}}\right) \]
                                      16. rem-square-sqrtN/A

                                        \[\leadsto \frac{1}{2} \cdot \mathsf{fma}\left(\sqrt{\color{blue}{p}}, \sqrt{p}, \left|r\right| - \sqrt{{\left(p - r\right)}^{2} + 4 \cdot {q}^{2}}\right) \]
                                      17. rem-square-sqrtN/A

                                        \[\leadsto \frac{1}{2} \cdot \mathsf{fma}\left(\sqrt{p}, \sqrt{\color{blue}{\sqrt{p} \cdot \sqrt{p}}}, \left|r\right| - \sqrt{{\left(p - r\right)}^{2} + 4 \cdot {q}^{2}}\right) \]
                                      18. sqrt-prodN/A

                                        \[\leadsto \frac{1}{2} \cdot \mathsf{fma}\left(\sqrt{p}, \sqrt{\color{blue}{\sqrt{p \cdot p}}}, \left|r\right| - \sqrt{{\left(p - r\right)}^{2} + 4 \cdot {q}^{2}}\right) \]
                                      19. rem-sqrt-square-revN/A

                                        \[\leadsto \frac{1}{2} \cdot \mathsf{fma}\left(\sqrt{p}, \sqrt{\color{blue}{\left|p\right|}}, \left|r\right| - \sqrt{{\left(p - r\right)}^{2} + 4 \cdot {q}^{2}}\right) \]
                                      20. lift-fabs.f64N/A

                                        \[\leadsto \frac{1}{2} \cdot \mathsf{fma}\left(\sqrt{p}, \sqrt{\color{blue}{\left|p\right|}}, \left|r\right| - \sqrt{{\left(p - r\right)}^{2} + 4 \cdot {q}^{2}}\right) \]
                                      21. lower-sqrt.f64N/A

                                        \[\leadsto \frac{1}{2} \cdot \mathsf{fma}\left(\sqrt{p}, \color{blue}{\sqrt{\left|p\right|}}, \left|r\right| - \sqrt{{\left(p - r\right)}^{2} + 4 \cdot {q}^{2}}\right) \]
                                      22. lift-fabs.f64N/A

                                        \[\leadsto \frac{1}{2} \cdot \mathsf{fma}\left(\sqrt{p}, \sqrt{\color{blue}{\left|p\right|}}, \left|r\right| - \sqrt{{\left(p - r\right)}^{2} + 4 \cdot {q}^{2}}\right) \]
                                      23. rem-sqrt-square-revN/A

                                        \[\leadsto \frac{1}{2} \cdot \mathsf{fma}\left(\sqrt{p}, \sqrt{\color{blue}{\sqrt{p \cdot p}}}, \left|r\right| - \sqrt{{\left(p - r\right)}^{2} + 4 \cdot {q}^{2}}\right) \]
                                      24. sqrt-prodN/A

                                        \[\leadsto \frac{1}{2} \cdot \mathsf{fma}\left(\sqrt{p}, \sqrt{\color{blue}{\sqrt{p} \cdot \sqrt{p}}}, \left|r\right| - \sqrt{{\left(p - r\right)}^{2} + 4 \cdot {q}^{2}}\right) \]
                                      25. rem-square-sqrtN/A

                                        \[\leadsto \frac{1}{2} \cdot \mathsf{fma}\left(\sqrt{p}, \sqrt{\color{blue}{p}}, \left|r\right| - \sqrt{{\left(p - r\right)}^{2} + 4 \cdot {q}^{2}}\right) \]
                                      26. lower--.f649.2

                                        \[\leadsto \frac{1}{2} \cdot \mathsf{fma}\left(\sqrt{p}, \sqrt{p}, \color{blue}{\left|r\right| - \sqrt{{\left(p - r\right)}^{2} + 4 \cdot {q}^{2}}}\right) \]
                                    4. Applied rewrites9.2%

                                      \[\leadsto \frac{1}{2} \cdot \color{blue}{\mathsf{fma}\left(\sqrt{p}, \sqrt{p}, r - \sqrt{\mathsf{fma}\left(q \cdot q, 4, {\left(p - r\right)}^{2}\right)}\right)} \]
                                    5. Taylor expanded in r around inf

                                      \[\leadsto \color{blue}{-1 \cdot \frac{{q}^{2}}{r} + \frac{1}{2} \cdot \left(p - -1 \cdot p\right)} \]
                                    6. Step-by-step derivation
                                      1. +-commutativeN/A

                                        \[\leadsto \color{blue}{\frac{1}{2} \cdot \left(p - -1 \cdot p\right) + -1 \cdot \frac{{q}^{2}}{r}} \]
                                      2. *-commutativeN/A

                                        \[\leadsto \color{blue}{\left(p - -1 \cdot p\right) \cdot \frac{1}{2}} + -1 \cdot \frac{{q}^{2}}{r} \]
                                      3. lower-fma.f64N/A

                                        \[\leadsto \color{blue}{\mathsf{fma}\left(p - -1 \cdot p, \frac{1}{2}, -1 \cdot \frac{{q}^{2}}{r}\right)} \]
                                      4. fp-cancel-sub-sign-invN/A

                                        \[\leadsto \mathsf{fma}\left(\color{blue}{p + \left(\mathsf{neg}\left(-1\right)\right) \cdot p}, \frac{1}{2}, -1 \cdot \frac{{q}^{2}}{r}\right) \]
                                      5. metadata-evalN/A

                                        \[\leadsto \mathsf{fma}\left(p + \color{blue}{1} \cdot p, \frac{1}{2}, -1 \cdot \frac{{q}^{2}}{r}\right) \]
                                      6. distribute-rgt1-inN/A

                                        \[\leadsto \mathsf{fma}\left(\color{blue}{\left(1 + 1\right) \cdot p}, \frac{1}{2}, -1 \cdot \frac{{q}^{2}}{r}\right) \]
                                      7. metadata-evalN/A

                                        \[\leadsto \mathsf{fma}\left(\color{blue}{2} \cdot p, \frac{1}{2}, -1 \cdot \frac{{q}^{2}}{r}\right) \]
                                      8. metadata-evalN/A

                                        \[\leadsto \mathsf{fma}\left(\color{blue}{\left(\mathsf{neg}\left(-2\right)\right)} \cdot p, \frac{1}{2}, -1 \cdot \frac{{q}^{2}}{r}\right) \]
                                      9. metadata-evalN/A

                                        \[\leadsto \mathsf{fma}\left(\left(\mathsf{neg}\left(\color{blue}{\left(-1 - 1\right)}\right)\right) \cdot p, \frac{1}{2}, -1 \cdot \frac{{q}^{2}}{r}\right) \]
                                      10. rem-square-sqrtN/A

                                        \[\leadsto \mathsf{fma}\left(\left(\mathsf{neg}\left(\left(\color{blue}{\sqrt{-1} \cdot \sqrt{-1}} - 1\right)\right)\right) \cdot p, \frac{1}{2}, -1 \cdot \frac{{q}^{2}}{r}\right) \]
                                      11. unpow2N/A

                                        \[\leadsto \mathsf{fma}\left(\left(\mathsf{neg}\left(\left(\color{blue}{{\left(\sqrt{-1}\right)}^{2}} - 1\right)\right)\right) \cdot p, \frac{1}{2}, -1 \cdot \frac{{q}^{2}}{r}\right) \]
                                      12. distribute-lft-neg-inN/A

                                        \[\leadsto \mathsf{fma}\left(\color{blue}{\mathsf{neg}\left(\left({\left(\sqrt{-1}\right)}^{2} - 1\right) \cdot p\right)}, \frac{1}{2}, -1 \cdot \frac{{q}^{2}}{r}\right) \]
                                      13. *-commutativeN/A

                                        \[\leadsto \mathsf{fma}\left(\mathsf{neg}\left(\color{blue}{p \cdot \left({\left(\sqrt{-1}\right)}^{2} - 1\right)}\right), \frac{1}{2}, -1 \cdot \frac{{q}^{2}}{r}\right) \]
                                      14. distribute-rgt-neg-inN/A

                                        \[\leadsto \mathsf{fma}\left(\color{blue}{p \cdot \left(\mathsf{neg}\left(\left({\left(\sqrt{-1}\right)}^{2} - 1\right)\right)\right)}, \frac{1}{2}, -1 \cdot \frac{{q}^{2}}{r}\right) \]
                                      15. unpow2N/A

                                        \[\leadsto \mathsf{fma}\left(p \cdot \left(\mathsf{neg}\left(\left(\color{blue}{\sqrt{-1} \cdot \sqrt{-1}} - 1\right)\right)\right), \frac{1}{2}, -1 \cdot \frac{{q}^{2}}{r}\right) \]
                                      16. rem-square-sqrtN/A

                                        \[\leadsto \mathsf{fma}\left(p \cdot \left(\mathsf{neg}\left(\left(\color{blue}{-1} - 1\right)\right)\right), \frac{1}{2}, -1 \cdot \frac{{q}^{2}}{r}\right) \]
                                      17. metadata-evalN/A

                                        \[\leadsto \mathsf{fma}\left(p \cdot \left(\mathsf{neg}\left(\color{blue}{-2}\right)\right), \frac{1}{2}, -1 \cdot \frac{{q}^{2}}{r}\right) \]
                                      18. metadata-evalN/A

                                        \[\leadsto \mathsf{fma}\left(p \cdot \color{blue}{2}, \frac{1}{2}, -1 \cdot \frac{{q}^{2}}{r}\right) \]
                                      19. lower-*.f64N/A

                                        \[\leadsto \mathsf{fma}\left(\color{blue}{p \cdot 2}, \frac{1}{2}, -1 \cdot \frac{{q}^{2}}{r}\right) \]
                                      20. associate-*r/N/A

                                        \[\leadsto \mathsf{fma}\left(p \cdot 2, \frac{1}{2}, \color{blue}{\frac{-1 \cdot {q}^{2}}{r}}\right) \]
                                      21. mul-1-negN/A

                                        \[\leadsto \mathsf{fma}\left(p \cdot 2, \frac{1}{2}, \frac{\color{blue}{\mathsf{neg}\left({q}^{2}\right)}}{r}\right) \]
                                    7. Applied rewrites26.4%

                                      \[\leadsto \color{blue}{\mathsf{fma}\left(p \cdot 2, 0.5, \frac{\left(-q\right) \cdot q}{r}\right)} \]
                                  3. Recombined 3 regimes into one program.
                                  4. Final simplification15.8%

                                    \[\leadsto \begin{array}{l} \mathbf{if}\;q \leq 5.5 \cdot 10^{-16}:\\ \;\;\;\;\left(\left(r - \left|r\right|\right) - \left(\left|p\right| - p\right)\right) \cdot -0.5\\ \mathbf{elif}\;q \leq 4.7 \cdot 10^{+25} \lor \neg \left(q \leq 2.05 \cdot 10^{+82}\right):\\ \;\;\;\;-q\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(p \cdot 2, 0.5, \frac{\left(-q\right) \cdot q}{r}\right)\\ \end{array} \]
                                  5. Add Preprocessing

                                  Alternative 6: 31.9% accurate, 10.0× speedup?

                                  \[\begin{array}{l} q_m = \left|q\right| \\ [p, r, q_m] = \mathsf{sort}([p, r, q_m])\\ \\ \begin{array}{l} \mathbf{if}\;q\_m \leq 5.5 \cdot 10^{-16}:\\ \;\;\;\;\left(\left(r - \left|r\right|\right) - \left(\left|p\right| - p\right)\right) \cdot -0.5\\ \mathbf{else}:\\ \;\;\;\;-q\_m\\ \end{array} \end{array} \]
                                  q_m = (fabs.f64 q)
                                  NOTE: p, r, and q_m should be sorted in increasing order before calling this function.
                                  (FPCore (p r q_m)
                                   :precision binary64
                                   (if (<= q_m 5.5e-16) (* (- (- r (fabs r)) (- (fabs p) p)) -0.5) (- q_m)))
                                  q_m = fabs(q);
                                  assert(p < r && r < q_m);
                                  double code(double p, double r, double q_m) {
                                  	double tmp;
                                  	if (q_m <= 5.5e-16) {
                                  		tmp = ((r - fabs(r)) - (fabs(p) - p)) * -0.5;
                                  	} else {
                                  		tmp = -q_m;
                                  	}
                                  	return tmp;
                                  }
                                  
                                  q_m =     private
                                  NOTE: p, r, and q_m should be sorted in increasing order before calling this function.
                                  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(p, r, q_m)
                                  use fmin_fmax_functions
                                      real(8), intent (in) :: p
                                      real(8), intent (in) :: r
                                      real(8), intent (in) :: q_m
                                      real(8) :: tmp
                                      if (q_m <= 5.5d-16) then
                                          tmp = ((r - abs(r)) - (abs(p) - p)) * (-0.5d0)
                                      else
                                          tmp = -q_m
                                      end if
                                      code = tmp
                                  end function
                                  
                                  q_m = Math.abs(q);
                                  assert p < r && r < q_m;
                                  public static double code(double p, double r, double q_m) {
                                  	double tmp;
                                  	if (q_m <= 5.5e-16) {
                                  		tmp = ((r - Math.abs(r)) - (Math.abs(p) - p)) * -0.5;
                                  	} else {
                                  		tmp = -q_m;
                                  	}
                                  	return tmp;
                                  }
                                  
                                  q_m = math.fabs(q)
                                  [p, r, q_m] = sort([p, r, q_m])
                                  def code(p, r, q_m):
                                  	tmp = 0
                                  	if q_m <= 5.5e-16:
                                  		tmp = ((r - math.fabs(r)) - (math.fabs(p) - p)) * -0.5
                                  	else:
                                  		tmp = -q_m
                                  	return tmp
                                  
                                  q_m = abs(q)
                                  p, r, q_m = sort([p, r, q_m])
                                  function code(p, r, q_m)
                                  	tmp = 0.0
                                  	if (q_m <= 5.5e-16)
                                  		tmp = Float64(Float64(Float64(r - abs(r)) - Float64(abs(p) - p)) * -0.5);
                                  	else
                                  		tmp = Float64(-q_m);
                                  	end
                                  	return tmp
                                  end
                                  
                                  q_m = abs(q);
                                  p, r, q_m = num2cell(sort([p, r, q_m])){:}
                                  function tmp_2 = code(p, r, q_m)
                                  	tmp = 0.0;
                                  	if (q_m <= 5.5e-16)
                                  		tmp = ((r - abs(r)) - (abs(p) - p)) * -0.5;
                                  	else
                                  		tmp = -q_m;
                                  	end
                                  	tmp_2 = tmp;
                                  end
                                  
                                  q_m = N[Abs[q], $MachinePrecision]
                                  NOTE: p, r, and q_m should be sorted in increasing order before calling this function.
                                  code[p_, r_, q$95$m_] := If[LessEqual[q$95$m, 5.5e-16], N[(N[(N[(r - N[Abs[r], $MachinePrecision]), $MachinePrecision] - N[(N[Abs[p], $MachinePrecision] - p), $MachinePrecision]), $MachinePrecision] * -0.5), $MachinePrecision], (-q$95$m)]
                                  
                                  \begin{array}{l}
                                  q_m = \left|q\right|
                                  \\
                                  [p, r, q_m] = \mathsf{sort}([p, r, q_m])\\
                                  \\
                                  \begin{array}{l}
                                  \mathbf{if}\;q\_m \leq 5.5 \cdot 10^{-16}:\\
                                  \;\;\;\;\left(\left(r - \left|r\right|\right) - \left(\left|p\right| - p\right)\right) \cdot -0.5\\
                                  
                                  \mathbf{else}:\\
                                  \;\;\;\;-q\_m\\
                                  
                                  
                                  \end{array}
                                  \end{array}
                                  
                                  Derivation
                                  1. Split input into 2 regimes
                                  2. if q < 5.49999999999999964e-16

                                    1. Initial program 22.1%

                                      \[\frac{1}{2} \cdot \left(\left(\left|p\right| + \left|r\right|\right) - \sqrt{{\left(p - r\right)}^{2} + 4 \cdot {q}^{2}}\right) \]
                                    2. Add Preprocessing
                                    3. Taylor expanded in r around inf

                                      \[\leadsto \color{blue}{r \cdot \left(\frac{1}{2} \cdot \frac{\left(\left|p\right| + \left|r\right|\right) - -1 \cdot p}{r} - \frac{1}{2}\right)} \]
                                    4. Step-by-step derivation
                                      1. *-commutativeN/A

                                        \[\leadsto \color{blue}{\left(\frac{1}{2} \cdot \frac{\left(\left|p\right| + \left|r\right|\right) - -1 \cdot p}{r} - \frac{1}{2}\right) \cdot r} \]
                                      2. lower-*.f64N/A

                                        \[\leadsto \color{blue}{\left(\frac{1}{2} \cdot \frac{\left(\left|p\right| + \left|r\right|\right) - -1 \cdot p}{r} - \frac{1}{2}\right) \cdot r} \]
                                    5. Applied rewrites9.6%

                                      \[\leadsto \color{blue}{\left(\frac{\left(\left|r\right| + p\right) + \left|p\right|}{r} \cdot 0.5 - 0.5\right) \cdot r} \]
                                    6. Taylor expanded in r around 0

                                      \[\leadsto \frac{-1}{2} \cdot r + \color{blue}{\frac{1}{2} \cdot \left(p + \left(\left|p\right| + \left|r\right|\right)\right)} \]
                                    7. Step-by-step derivation
                                      1. Applied rewrites9.6%

                                        \[\leadsto -0.5 \cdot \color{blue}{\left(r - \left(\left(p + \left|r\right|\right) + \left|p\right|\right)\right)} \]
                                      2. Step-by-step derivation
                                        1. Applied rewrites31.4%

                                          \[\leadsto \color{blue}{\left(\left(r - \left|r\right|\right) - \left(\left|p\right| + p\right)\right) \cdot -0.5} \]

                                        if 5.49999999999999964e-16 < q

                                        1. Initial program 21.9%

                                          \[\frac{1}{2} \cdot \left(\left(\left|p\right| + \left|r\right|\right) - \sqrt{{\left(p - r\right)}^{2} + 4 \cdot {q}^{2}}\right) \]
                                        2. Add Preprocessing
                                        3. Taylor expanded in q around inf

                                          \[\leadsto \color{blue}{-1 \cdot q} \]
                                        4. Step-by-step derivation
                                          1. mul-1-negN/A

                                            \[\leadsto \color{blue}{\mathsf{neg}\left(q\right)} \]
                                          2. lower-neg.f6451.3

                                            \[\leadsto \color{blue}{-q} \]
                                        5. Applied rewrites51.3%

                                          \[\leadsto \color{blue}{-q} \]
                                      3. Recombined 2 regimes into one program.
                                      4. Final simplification15.5%

                                        \[\leadsto \begin{array}{l} \mathbf{if}\;q \leq 5.5 \cdot 10^{-16}:\\ \;\;\;\;\left(\left(r - \left|r\right|\right) - \left(\left|p\right| - p\right)\right) \cdot -0.5\\ \mathbf{else}:\\ \;\;\;\;-q\\ \end{array} \]
                                      5. Add Preprocessing

                                      Alternative 7: 48.0% accurate, 14.7× speedup?

                                      \[\begin{array}{l} q_m = \left|q\right| \\ [p, r, q_m] = \mathsf{sort}([p, r, q_m])\\ \\ \begin{array}{l} \mathbf{if}\;q\_m \leq 9.6 \cdot 10^{-290}:\\ \;\;\;\;\left(p \cdot 2\right) \cdot 0.5\\ \mathbf{elif}\;q\_m \leq 1.4 \cdot 10^{-55}:\\ \;\;\;\;0\\ \mathbf{else}:\\ \;\;\;\;-q\_m\\ \end{array} \end{array} \]
                                      q_m = (fabs.f64 q)
                                      NOTE: p, r, and q_m should be sorted in increasing order before calling this function.
                                      (FPCore (p r q_m)
                                       :precision binary64
                                       (if (<= q_m 9.6e-290) (* (* p 2.0) 0.5) (if (<= q_m 1.4e-55) 0.0 (- q_m))))
                                      q_m = fabs(q);
                                      assert(p < r && r < q_m);
                                      double code(double p, double r, double q_m) {
                                      	double tmp;
                                      	if (q_m <= 9.6e-290) {
                                      		tmp = (p * 2.0) * 0.5;
                                      	} else if (q_m <= 1.4e-55) {
                                      		tmp = 0.0;
                                      	} else {
                                      		tmp = -q_m;
                                      	}
                                      	return tmp;
                                      }
                                      
                                      q_m =     private
                                      NOTE: p, r, and q_m should be sorted in increasing order before calling this function.
                                      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(p, r, q_m)
                                      use fmin_fmax_functions
                                          real(8), intent (in) :: p
                                          real(8), intent (in) :: r
                                          real(8), intent (in) :: q_m
                                          real(8) :: tmp
                                          if (q_m <= 9.6d-290) then
                                              tmp = (p * 2.0d0) * 0.5d0
                                          else if (q_m <= 1.4d-55) then
                                              tmp = 0.0d0
                                          else
                                              tmp = -q_m
                                          end if
                                          code = tmp
                                      end function
                                      
                                      q_m = Math.abs(q);
                                      assert p < r && r < q_m;
                                      public static double code(double p, double r, double q_m) {
                                      	double tmp;
                                      	if (q_m <= 9.6e-290) {
                                      		tmp = (p * 2.0) * 0.5;
                                      	} else if (q_m <= 1.4e-55) {
                                      		tmp = 0.0;
                                      	} else {
                                      		tmp = -q_m;
                                      	}
                                      	return tmp;
                                      }
                                      
                                      q_m = math.fabs(q)
                                      [p, r, q_m] = sort([p, r, q_m])
                                      def code(p, r, q_m):
                                      	tmp = 0
                                      	if q_m <= 9.6e-290:
                                      		tmp = (p * 2.0) * 0.5
                                      	elif q_m <= 1.4e-55:
                                      		tmp = 0.0
                                      	else:
                                      		tmp = -q_m
                                      	return tmp
                                      
                                      q_m = abs(q)
                                      p, r, q_m = sort([p, r, q_m])
                                      function code(p, r, q_m)
                                      	tmp = 0.0
                                      	if (q_m <= 9.6e-290)
                                      		tmp = Float64(Float64(p * 2.0) * 0.5);
                                      	elseif (q_m <= 1.4e-55)
                                      		tmp = 0.0;
                                      	else
                                      		tmp = Float64(-q_m);
                                      	end
                                      	return tmp
                                      end
                                      
                                      q_m = abs(q);
                                      p, r, q_m = num2cell(sort([p, r, q_m])){:}
                                      function tmp_2 = code(p, r, q_m)
                                      	tmp = 0.0;
                                      	if (q_m <= 9.6e-290)
                                      		tmp = (p * 2.0) * 0.5;
                                      	elseif (q_m <= 1.4e-55)
                                      		tmp = 0.0;
                                      	else
                                      		tmp = -q_m;
                                      	end
                                      	tmp_2 = tmp;
                                      end
                                      
                                      q_m = N[Abs[q], $MachinePrecision]
                                      NOTE: p, r, and q_m should be sorted in increasing order before calling this function.
                                      code[p_, r_, q$95$m_] := If[LessEqual[q$95$m, 9.6e-290], N[(N[(p * 2.0), $MachinePrecision] * 0.5), $MachinePrecision], If[LessEqual[q$95$m, 1.4e-55], 0.0, (-q$95$m)]]
                                      
                                      \begin{array}{l}
                                      q_m = \left|q\right|
                                      \\
                                      [p, r, q_m] = \mathsf{sort}([p, r, q_m])\\
                                      \\
                                      \begin{array}{l}
                                      \mathbf{if}\;q\_m \leq 9.6 \cdot 10^{-290}:\\
                                      \;\;\;\;\left(p \cdot 2\right) \cdot 0.5\\
                                      
                                      \mathbf{elif}\;q\_m \leq 1.4 \cdot 10^{-55}:\\
                                      \;\;\;\;0\\
                                      
                                      \mathbf{else}:\\
                                      \;\;\;\;-q\_m\\
                                      
                                      
                                      \end{array}
                                      \end{array}
                                      
                                      Derivation
                                      1. Split input into 3 regimes
                                      2. if q < 9.6000000000000002e-290

                                        1. Initial program 24.6%

                                          \[\frac{1}{2} \cdot \left(\left(\left|p\right| + \left|r\right|\right) - \sqrt{{\left(p - r\right)}^{2} + 4 \cdot {q}^{2}}\right) \]
                                        2. Add Preprocessing
                                        3. Step-by-step derivation
                                          1. lift--.f64N/A

                                            \[\leadsto \frac{1}{2} \cdot \color{blue}{\left(\left(\left|p\right| + \left|r\right|\right) - \sqrt{{\left(p - r\right)}^{2} + 4 \cdot {q}^{2}}\right)} \]
                                          2. lift-+.f64N/A

                                            \[\leadsto \frac{1}{2} \cdot \left(\color{blue}{\left(\left|p\right| + \left|r\right|\right)} - \sqrt{{\left(p - r\right)}^{2} + 4 \cdot {q}^{2}}\right) \]
                                          3. associate--l+N/A

                                            \[\leadsto \frac{1}{2} \cdot \color{blue}{\left(\left|p\right| + \left(\left|r\right| - \sqrt{{\left(p - r\right)}^{2} + 4 \cdot {q}^{2}}\right)\right)} \]
                                          4. lift-fabs.f64N/A

                                            \[\leadsto \frac{1}{2} \cdot \left(\color{blue}{\left|p\right|} + \left(\left|r\right| - \sqrt{{\left(p - r\right)}^{2} + 4 \cdot {q}^{2}}\right)\right) \]
                                          5. rem-sqrt-square-revN/A

                                            \[\leadsto \frac{1}{2} \cdot \left(\color{blue}{\sqrt{p \cdot p}} + \left(\left|r\right| - \sqrt{{\left(p - r\right)}^{2} + 4 \cdot {q}^{2}}\right)\right) \]
                                          6. sqrt-prodN/A

                                            \[\leadsto \frac{1}{2} \cdot \left(\color{blue}{\sqrt{p} \cdot \sqrt{p}} + \left(\left|r\right| - \sqrt{{\left(p - r\right)}^{2} + 4 \cdot {q}^{2}}\right)\right) \]
                                          7. lower-fma.f64N/A

                                            \[\leadsto \frac{1}{2} \cdot \color{blue}{\mathsf{fma}\left(\sqrt{p}, \sqrt{p}, \left|r\right| - \sqrt{{\left(p - r\right)}^{2} + 4 \cdot {q}^{2}}\right)} \]
                                          8. rem-square-sqrtN/A

                                            \[\leadsto \frac{1}{2} \cdot \mathsf{fma}\left(\sqrt{\color{blue}{\sqrt{p} \cdot \sqrt{p}}}, \sqrt{p}, \left|r\right| - \sqrt{{\left(p - r\right)}^{2} + 4 \cdot {q}^{2}}\right) \]
                                          9. sqrt-prodN/A

                                            \[\leadsto \frac{1}{2} \cdot \mathsf{fma}\left(\sqrt{\color{blue}{\sqrt{p \cdot p}}}, \sqrt{p}, \left|r\right| - \sqrt{{\left(p - r\right)}^{2} + 4 \cdot {q}^{2}}\right) \]
                                          10. rem-sqrt-square-revN/A

                                            \[\leadsto \frac{1}{2} \cdot \mathsf{fma}\left(\sqrt{\color{blue}{\left|p\right|}}, \sqrt{p}, \left|r\right| - \sqrt{{\left(p - r\right)}^{2} + 4 \cdot {q}^{2}}\right) \]
                                          11. lift-fabs.f64N/A

                                            \[\leadsto \frac{1}{2} \cdot \mathsf{fma}\left(\sqrt{\color{blue}{\left|p\right|}}, \sqrt{p}, \left|r\right| - \sqrt{{\left(p - r\right)}^{2} + 4 \cdot {q}^{2}}\right) \]
                                          12. lower-sqrt.f64N/A

                                            \[\leadsto \frac{1}{2} \cdot \mathsf{fma}\left(\color{blue}{\sqrt{\left|p\right|}}, \sqrt{p}, \left|r\right| - \sqrt{{\left(p - r\right)}^{2} + 4 \cdot {q}^{2}}\right) \]
                                          13. lift-fabs.f64N/A

                                            \[\leadsto \frac{1}{2} \cdot \mathsf{fma}\left(\sqrt{\color{blue}{\left|p\right|}}, \sqrt{p}, \left|r\right| - \sqrt{{\left(p - r\right)}^{2} + 4 \cdot {q}^{2}}\right) \]
                                          14. rem-sqrt-square-revN/A

                                            \[\leadsto \frac{1}{2} \cdot \mathsf{fma}\left(\sqrt{\color{blue}{\sqrt{p \cdot p}}}, \sqrt{p}, \left|r\right| - \sqrt{{\left(p - r\right)}^{2} + 4 \cdot {q}^{2}}\right) \]
                                          15. sqrt-prodN/A

                                            \[\leadsto \frac{1}{2} \cdot \mathsf{fma}\left(\sqrt{\color{blue}{\sqrt{p} \cdot \sqrt{p}}}, \sqrt{p}, \left|r\right| - \sqrt{{\left(p - r\right)}^{2} + 4 \cdot {q}^{2}}\right) \]
                                          16. rem-square-sqrtN/A

                                            \[\leadsto \frac{1}{2} \cdot \mathsf{fma}\left(\sqrt{\color{blue}{p}}, \sqrt{p}, \left|r\right| - \sqrt{{\left(p - r\right)}^{2} + 4 \cdot {q}^{2}}\right) \]
                                          17. rem-square-sqrtN/A

                                            \[\leadsto \frac{1}{2} \cdot \mathsf{fma}\left(\sqrt{p}, \sqrt{\color{blue}{\sqrt{p} \cdot \sqrt{p}}}, \left|r\right| - \sqrt{{\left(p - r\right)}^{2} + 4 \cdot {q}^{2}}\right) \]
                                          18. sqrt-prodN/A

                                            \[\leadsto \frac{1}{2} \cdot \mathsf{fma}\left(\sqrt{p}, \sqrt{\color{blue}{\sqrt{p \cdot p}}}, \left|r\right| - \sqrt{{\left(p - r\right)}^{2} + 4 \cdot {q}^{2}}\right) \]
                                          19. rem-sqrt-square-revN/A

                                            \[\leadsto \frac{1}{2} \cdot \mathsf{fma}\left(\sqrt{p}, \sqrt{\color{blue}{\left|p\right|}}, \left|r\right| - \sqrt{{\left(p - r\right)}^{2} + 4 \cdot {q}^{2}}\right) \]
                                          20. lift-fabs.f64N/A

                                            \[\leadsto \frac{1}{2} \cdot \mathsf{fma}\left(\sqrt{p}, \sqrt{\color{blue}{\left|p\right|}}, \left|r\right| - \sqrt{{\left(p - r\right)}^{2} + 4 \cdot {q}^{2}}\right) \]
                                          21. lower-sqrt.f64N/A

                                            \[\leadsto \frac{1}{2} \cdot \mathsf{fma}\left(\sqrt{p}, \color{blue}{\sqrt{\left|p\right|}}, \left|r\right| - \sqrt{{\left(p - r\right)}^{2} + 4 \cdot {q}^{2}}\right) \]
                                          22. lift-fabs.f64N/A

                                            \[\leadsto \frac{1}{2} \cdot \mathsf{fma}\left(\sqrt{p}, \sqrt{\color{blue}{\left|p\right|}}, \left|r\right| - \sqrt{{\left(p - r\right)}^{2} + 4 \cdot {q}^{2}}\right) \]
                                          23. rem-sqrt-square-revN/A

                                            \[\leadsto \frac{1}{2} \cdot \mathsf{fma}\left(\sqrt{p}, \sqrt{\color{blue}{\sqrt{p \cdot p}}}, \left|r\right| - \sqrt{{\left(p - r\right)}^{2} + 4 \cdot {q}^{2}}\right) \]
                                          24. sqrt-prodN/A

                                            \[\leadsto \frac{1}{2} \cdot \mathsf{fma}\left(\sqrt{p}, \sqrt{\color{blue}{\sqrt{p} \cdot \sqrt{p}}}, \left|r\right| - \sqrt{{\left(p - r\right)}^{2} + 4 \cdot {q}^{2}}\right) \]
                                          25. rem-square-sqrtN/A

                                            \[\leadsto \frac{1}{2} \cdot \mathsf{fma}\left(\sqrt{p}, \sqrt{\color{blue}{p}}, \left|r\right| - \sqrt{{\left(p - r\right)}^{2} + 4 \cdot {q}^{2}}\right) \]
                                          26. lower--.f649.8

                                            \[\leadsto \frac{1}{2} \cdot \mathsf{fma}\left(\sqrt{p}, \sqrt{p}, \color{blue}{\left|r\right| - \sqrt{{\left(p - r\right)}^{2} + 4 \cdot {q}^{2}}}\right) \]
                                        4. Applied rewrites9.8%

                                          \[\leadsto \frac{1}{2} \cdot \color{blue}{\mathsf{fma}\left(\sqrt{p}, \sqrt{p}, r - \sqrt{\mathsf{fma}\left(q \cdot q, 4, {\left(p - r\right)}^{2}\right)}\right)} \]
                                        5. Taylor expanded in r around inf

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

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

                                            \[\leadsto \color{blue}{\left(p - -1 \cdot p\right) \cdot \frac{1}{2}} \]
                                          3. fp-cancel-sub-sign-invN/A

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

                                            \[\leadsto \left(p + \color{blue}{1} \cdot p\right) \cdot \frac{1}{2} \]
                                          5. distribute-rgt1-inN/A

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

                                            \[\leadsto \left(\color{blue}{2} \cdot p\right) \cdot \frac{1}{2} \]
                                          7. metadata-evalN/A

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

                                            \[\leadsto \left(\left(\mathsf{neg}\left(\color{blue}{\left(-1 - 1\right)}\right)\right) \cdot p\right) \cdot \frac{1}{2} \]
                                          9. rem-square-sqrtN/A

                                            \[\leadsto \left(\left(\mathsf{neg}\left(\left(\color{blue}{\sqrt{-1} \cdot \sqrt{-1}} - 1\right)\right)\right) \cdot p\right) \cdot \frac{1}{2} \]
                                          10. unpow2N/A

                                            \[\leadsto \left(\left(\mathsf{neg}\left(\left(\color{blue}{{\left(\sqrt{-1}\right)}^{2}} - 1\right)\right)\right) \cdot p\right) \cdot \frac{1}{2} \]
                                          11. distribute-lft-neg-inN/A

                                            \[\leadsto \color{blue}{\left(\mathsf{neg}\left(\left({\left(\sqrt{-1}\right)}^{2} - 1\right) \cdot p\right)\right)} \cdot \frac{1}{2} \]
                                          12. *-commutativeN/A

                                            \[\leadsto \left(\mathsf{neg}\left(\color{blue}{p \cdot \left({\left(\sqrt{-1}\right)}^{2} - 1\right)}\right)\right) \cdot \frac{1}{2} \]
                                          13. distribute-rgt-neg-inN/A

                                            \[\leadsto \color{blue}{\left(p \cdot \left(\mathsf{neg}\left(\left({\left(\sqrt{-1}\right)}^{2} - 1\right)\right)\right)\right)} \cdot \frac{1}{2} \]
                                          14. unpow2N/A

                                            \[\leadsto \left(p \cdot \left(\mathsf{neg}\left(\left(\color{blue}{\sqrt{-1} \cdot \sqrt{-1}} - 1\right)\right)\right)\right) \cdot \frac{1}{2} \]
                                          15. rem-square-sqrtN/A

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

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

                                            \[\leadsto \left(p \cdot \color{blue}{2}\right) \cdot \frac{1}{2} \]
                                          18. lower-*.f6415.2

                                            \[\leadsto \color{blue}{\left(p \cdot 2\right)} \cdot 0.5 \]
                                        7. Applied rewrites15.2%

                                          \[\leadsto \color{blue}{\left(p \cdot 2\right) \cdot 0.5} \]

                                        if 9.6000000000000002e-290 < q < 1.39999999999999992e-55

                                        1. Initial program 14.5%

                                          \[\frac{1}{2} \cdot \left(\left(\left|p\right| + \left|r\right|\right) - \sqrt{{\left(p - r\right)}^{2} + 4 \cdot {q}^{2}}\right) \]
                                        2. Add Preprocessing
                                        3. Taylor expanded in r around inf

                                          \[\leadsto \color{blue}{r \cdot \left(\frac{1}{2} \cdot \frac{\left(\left|p\right| + \left|r\right|\right) - -1 \cdot p}{r} - \frac{1}{2}\right)} \]
                                        4. Step-by-step derivation
                                          1. *-commutativeN/A

                                            \[\leadsto \color{blue}{\left(\frac{1}{2} \cdot \frac{\left(\left|p\right| + \left|r\right|\right) - -1 \cdot p}{r} - \frac{1}{2}\right) \cdot r} \]
                                          2. lower-*.f64N/A

                                            \[\leadsto \color{blue}{\left(\frac{1}{2} \cdot \frac{\left(\left|p\right| + \left|r\right|\right) - -1 \cdot p}{r} - \frac{1}{2}\right) \cdot r} \]
                                        5. Applied rewrites15.6%

                                          \[\leadsto \color{blue}{\left(\frac{\left(\left|r\right| + p\right) + \left|p\right|}{r} \cdot 0.5 - 0.5\right) \cdot r} \]
                                        6. Taylor expanded in r around 0

                                          \[\leadsto \frac{-1}{2} \cdot r + \color{blue}{\frac{1}{2} \cdot \left(p + \left(\left|p\right| + \left|r\right|\right)\right)} \]
                                        7. Step-by-step derivation
                                          1. Applied rewrites15.7%

                                            \[\leadsto -0.5 \cdot \color{blue}{\left(r - \left(\left(p + \left|r\right|\right) + \left|p\right|\right)\right)} \]
                                          2. Step-by-step derivation
                                            1. Applied rewrites11.6%

                                              \[\leadsto -0.5 \cdot \left(r - \mathsf{fma}\left(\sqrt{-p}, \sqrt{-p}, \left|r\right| + p\right)\right) \]
                                            2. Taylor expanded in p around inf

                                              \[\leadsto \frac{1}{2} \cdot \left(p \cdot \color{blue}{\left(1 + {\left(\sqrt{-1}\right)}^{2}\right)}\right) \]
                                            3. Step-by-step derivation
                                              1. Applied rewrites38.3%

                                                \[\leadsto 0 \cdot p \]

                                              if 1.39999999999999992e-55 < q

                                              1. Initial program 21.8%

                                                \[\frac{1}{2} \cdot \left(\left(\left|p\right| + \left|r\right|\right) - \sqrt{{\left(p - r\right)}^{2} + 4 \cdot {q}^{2}}\right) \]
                                              2. Add Preprocessing
                                              3. Taylor expanded in q around inf

                                                \[\leadsto \color{blue}{-1 \cdot q} \]
                                              4. Step-by-step derivation
                                                1. mul-1-negN/A

                                                  \[\leadsto \color{blue}{\mathsf{neg}\left(q\right)} \]
                                                2. lower-neg.f6447.0

                                                  \[\leadsto \color{blue}{-q} \]
                                              5. Applied rewrites47.0%

                                                \[\leadsto \color{blue}{-q} \]
                                            4. Recombined 3 regimes into one program.
                                            5. Final simplification28.6%

                                              \[\leadsto \begin{array}{l} \mathbf{if}\;q \leq 9.6 \cdot 10^{-290}:\\ \;\;\;\;\left(p \cdot 2\right) \cdot 0.5\\ \mathbf{elif}\;q \leq 1.4 \cdot 10^{-55}:\\ \;\;\;\;0\\ \mathbf{else}:\\ \;\;\;\;-q\\ \end{array} \]
                                            6. Add Preprocessing

                                            Alternative 8: 35.4% accurate, 83.3× speedup?

                                            \[\begin{array}{l} q_m = \left|q\right| \\ [p, r, q_m] = \mathsf{sort}([p, r, q_m])\\ \\ -q\_m \end{array} \]
                                            q_m = (fabs.f64 q)
                                            NOTE: p, r, and q_m should be sorted in increasing order before calling this function.
                                            (FPCore (p r q_m) :precision binary64 (- q_m))
                                            q_m = fabs(q);
                                            assert(p < r && r < q_m);
                                            double code(double p, double r, double q_m) {
                                            	return -q_m;
                                            }
                                            
                                            q_m =     private
                                            NOTE: p, r, and q_m should be sorted in increasing order before calling this function.
                                            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(p, r, q_m)
                                            use fmin_fmax_functions
                                                real(8), intent (in) :: p
                                                real(8), intent (in) :: r
                                                real(8), intent (in) :: q_m
                                                code = -q_m
                                            end function
                                            
                                            q_m = Math.abs(q);
                                            assert p < r && r < q_m;
                                            public static double code(double p, double r, double q_m) {
                                            	return -q_m;
                                            }
                                            
                                            q_m = math.fabs(q)
                                            [p, r, q_m] = sort([p, r, q_m])
                                            def code(p, r, q_m):
                                            	return -q_m
                                            
                                            q_m = abs(q)
                                            p, r, q_m = sort([p, r, q_m])
                                            function code(p, r, q_m)
                                            	return Float64(-q_m)
                                            end
                                            
                                            q_m = abs(q);
                                            p, r, q_m = num2cell(sort([p, r, q_m])){:}
                                            function tmp = code(p, r, q_m)
                                            	tmp = -q_m;
                                            end
                                            
                                            q_m = N[Abs[q], $MachinePrecision]
                                            NOTE: p, r, and q_m should be sorted in increasing order before calling this function.
                                            code[p_, r_, q$95$m_] := (-q$95$m)
                                            
                                            \begin{array}{l}
                                            q_m = \left|q\right|
                                            \\
                                            [p, r, q_m] = \mathsf{sort}([p, r, q_m])\\
                                            \\
                                            -q\_m
                                            \end{array}
                                            
                                            Derivation
                                            1. Initial program 22.1%

                                              \[\frac{1}{2} \cdot \left(\left(\left|p\right| + \left|r\right|\right) - \sqrt{{\left(p - r\right)}^{2} + 4 \cdot {q}^{2}}\right) \]
                                            2. Add Preprocessing
                                            3. Taylor expanded in q around inf

                                              \[\leadsto \color{blue}{-1 \cdot q} \]
                                            4. Step-by-step derivation
                                              1. mul-1-negN/A

                                                \[\leadsto \color{blue}{\mathsf{neg}\left(q\right)} \]
                                              2. lower-neg.f6417.0

                                                \[\leadsto \color{blue}{-q} \]
                                            5. Applied rewrites17.0%

                                              \[\leadsto \color{blue}{-q} \]
                                            6. Add Preprocessing

                                            Reproduce

                                            ?
                                            herbie shell --seed 2024350 
                                            (FPCore (p r q)
                                              :name "1/2(abs(p)+abs(r) - sqrt((p-r)^2 + 4q^2))"
                                              :precision binary64
                                              (* (/ 1.0 2.0) (- (+ (fabs p) (fabs r)) (sqrt (+ (pow (- p r) 2.0) (* 4.0 (pow q 2.0)))))))