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

Percentage Accurate: 24.2% → 79.4%
Time: 9.0s
Alternatives: 10
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 10 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.2% 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: 79.4% accurate, 1.9× 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 2.9 \cdot 10^{+63}:\\ \;\;\;\;\mathsf{fma}\left(\left(p + \left|p\right|\right) + \left(\left|r\right| - r\right), 0.5, \frac{q\_m \cdot q\_m}{\left(-r\right) + p}\right)\\ \mathbf{else}:\\ \;\;\;\;\left(\left(\left|r\right| + \left|p\right|\right) - \mathsf{hypot}\left(q\_m \cdot -2, r - p\right)\right) \cdot 0.5\\ \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 2.9e+63)
   (fma (+ (+ p (fabs p)) (- (fabs r) r)) 0.5 (/ (* q_m q_m) (+ (- r) p)))
   (* (- (+ (fabs r) (fabs p)) (hypot (* q_m -2.0) (- r p))) 0.5)))
q_m = fabs(q);
assert(p < r && r < q_m);
double code(double p, double r, double q_m) {
	double tmp;
	if (q_m <= 2.9e+63) {
		tmp = fma(((p + fabs(p)) + (fabs(r) - r)), 0.5, ((q_m * q_m) / (-r + p)));
	} else {
		tmp = ((fabs(r) + fabs(p)) - hypot((q_m * -2.0), (r - p))) * 0.5;
	}
	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 <= 2.9e+63)
		tmp = fma(Float64(Float64(p + abs(p)) + Float64(abs(r) - r)), 0.5, Float64(Float64(q_m * q_m) / Float64(Float64(-r) + p)));
	else
		tmp = Float64(Float64(Float64(abs(r) + abs(p)) - hypot(Float64(q_m * -2.0), Float64(r - p))) * 0.5);
	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, 2.9e+63], N[(N[(N[(p + N[Abs[p], $MachinePrecision]), $MachinePrecision] + N[(N[Abs[r], $MachinePrecision] - r), $MachinePrecision]), $MachinePrecision] * 0.5 + N[(N[(q$95$m * q$95$m), $MachinePrecision] / N[((-r) + p), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(N[Abs[r], $MachinePrecision] + N[Abs[p], $MachinePrecision]), $MachinePrecision] - N[Sqrt[N[(q$95$m * -2.0), $MachinePrecision] ^ 2 + N[(r - p), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision] * 0.5), $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 2.9 \cdot 10^{+63}:\\
\;\;\;\;\mathsf{fma}\left(\left(p + \left|p\right|\right) + \left(\left|r\right| - r\right), 0.5, \frac{q\_m \cdot q\_m}{\left(-r\right) + p}\right)\\

\mathbf{else}:\\
\;\;\;\;\left(\left(\left|r\right| + \left|p\right|\right) - \mathsf{hypot}\left(q\_m \cdot -2, r - p\right)\right) \cdot 0.5\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if q < 2.8999999999999999e63

    1. Initial program 26.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. Applied rewrites52.7%

      \[\leadsto \color{blue}{\left(\left(\left|r\right| + \left|p\right|\right) - \mathsf{hypot}\left(q \cdot -2, r - p\right)\right) \cdot 0.5} \]
    3. Add Preprocessing
    4. Taylor expanded in q around 0

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

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

      if 2.8999999999999999e63 < q

      1. Initial program 35.4%

        \[\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. Applied rewrites73.1%

        \[\leadsto \color{blue}{\left(\left(\left|r\right| + \left|p\right|\right) - \mathsf{hypot}\left(q \cdot -2, r - p\right)\right) \cdot 0.5} \]
      3. Add Preprocessing
    6. Recombined 2 regimes into one program.
    7. Final simplification48.9%

      \[\leadsto \begin{array}{l} \mathbf{if}\;q \leq 2.9 \cdot 10^{+63}:\\ \;\;\;\;\mathsf{fma}\left(\left(p + \left|p\right|\right) + \left(\left|r\right| - r\right), 0.5, \frac{q \cdot q}{\left(-r\right) + p}\right)\\ \mathbf{else}:\\ \;\;\;\;\left(\left(\left|r\right| + \left|p\right|\right) - \mathsf{hypot}\left(q \cdot -2, r - p\right)\right) \cdot 0.5\\ \end{array} \]
    8. Add Preprocessing

    Alternative 2: 78.8% accurate, 2.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 2.9 \cdot 10^{+63}:\\ \;\;\;\;\mathsf{fma}\left(\left(p + \left|p\right|\right) + \left(\left|r\right| - r\right), 0.5, \frac{q\_m \cdot q\_m}{\left(-r\right) + p}\right)\\ \mathbf{else}:\\ \;\;\;\;\left(\left(\left|p\right| + \left|r\right|\right) - \mathsf{hypot}\left(-2 \cdot q\_m, p\right)\right) \cdot 0.5\\ \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 2.9e+63)
       (fma (+ (+ p (fabs p)) (- (fabs r) r)) 0.5 (/ (* q_m q_m) (+ (- r) p)))
       (* (- (+ (fabs p) (fabs r)) (hypot (* -2.0 q_m) p)) 0.5)))
    q_m = fabs(q);
    assert(p < r && r < q_m);
    double code(double p, double r, double q_m) {
    	double tmp;
    	if (q_m <= 2.9e+63) {
    		tmp = fma(((p + fabs(p)) + (fabs(r) - r)), 0.5, ((q_m * q_m) / (-r + p)));
    	} else {
    		tmp = ((fabs(p) + fabs(r)) - hypot((-2.0 * q_m), p)) * 0.5;
    	}
    	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 <= 2.9e+63)
    		tmp = fma(Float64(Float64(p + abs(p)) + Float64(abs(r) - r)), 0.5, Float64(Float64(q_m * q_m) / Float64(Float64(-r) + p)));
    	else
    		tmp = Float64(Float64(Float64(abs(p) + abs(r)) - hypot(Float64(-2.0 * q_m), p)) * 0.5);
    	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, 2.9e+63], N[(N[(N[(p + N[Abs[p], $MachinePrecision]), $MachinePrecision] + N[(N[Abs[r], $MachinePrecision] - r), $MachinePrecision]), $MachinePrecision] * 0.5 + N[(N[(q$95$m * q$95$m), $MachinePrecision] / N[((-r) + p), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(N[Abs[p], $MachinePrecision] + N[Abs[r], $MachinePrecision]), $MachinePrecision] - N[Sqrt[N[(-2.0 * q$95$m), $MachinePrecision] ^ 2 + p ^ 2], $MachinePrecision]), $MachinePrecision] * 0.5), $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 2.9 \cdot 10^{+63}:\\
    \;\;\;\;\mathsf{fma}\left(\left(p + \left|p\right|\right) + \left(\left|r\right| - r\right), 0.5, \frac{q\_m \cdot q\_m}{\left(-r\right) + p}\right)\\
    
    \mathbf{else}:\\
    \;\;\;\;\left(\left(\left|p\right| + \left|r\right|\right) - \mathsf{hypot}\left(-2 \cdot q\_m, p\right)\right) \cdot 0.5\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 2 regimes
    2. if q < 2.8999999999999999e63

      1. Initial program 26.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. Applied rewrites52.7%

        \[\leadsto \color{blue}{\left(\left(\left|r\right| + \left|p\right|\right) - \mathsf{hypot}\left(q \cdot -2, r - p\right)\right) \cdot 0.5} \]
      3. Add Preprocessing
      4. Taylor expanded in q around 0

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

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

        if 2.8999999999999999e63 < q

        1. Initial program 35.4%

          \[\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. Applied rewrites73.1%

          \[\leadsto \color{blue}{\left(\left(\left|r\right| + \left|p\right|\right) - \mathsf{hypot}\left(q \cdot -2, r - p\right)\right) \cdot 0.5} \]
        3. Add Preprocessing
        4. Taylor expanded in r around 0

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

            \[\leadsto \color{blue}{\left(\left(\left|p\right| + \left|r\right|\right) - \mathsf{hypot}\left(-2 \cdot q, p\right)\right)} \cdot 0.5 \]
        6. Recombined 2 regimes into one program.
        7. Final simplification48.6%

          \[\leadsto \begin{array}{l} \mathbf{if}\;q \leq 2.9 \cdot 10^{+63}:\\ \;\;\;\;\mathsf{fma}\left(\left(p + \left|p\right|\right) + \left(\left|r\right| - r\right), 0.5, \frac{q \cdot q}{\left(-r\right) + p}\right)\\ \mathbf{else}:\\ \;\;\;\;\left(\left(\left|p\right| + \left|r\right|\right) - \mathsf{hypot}\left(-2 \cdot q, p\right)\right) \cdot 0.5\\ \end{array} \]
        8. Add Preprocessing

        Alternative 3: 78.0% accurate, 5.3× 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.12 \cdot 10^{+52}:\\ \;\;\;\;\mathsf{fma}\left(\left(p + \left|p\right|\right) + \left(\left|r\right| - r\right), 0.5, \frac{q\_m \cdot q\_m}{\left(-r\right) + p}\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.12e+52)
           (fma (+ (+ p (fabs p)) (- (fabs r) r)) 0.5 (/ (* q_m q_m) (+ (- r) p)))
           (- 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.12e+52) {
        		tmp = fma(((p + fabs(p)) + (fabs(r) - r)), 0.5, ((q_m * q_m) / (-r + p)));
        	} 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.12e+52)
        		tmp = fma(Float64(Float64(p + abs(p)) + Float64(abs(r) - r)), 0.5, Float64(Float64(q_m * q_m) / Float64(Float64(-r) + p)));
        	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.12e+52], N[(N[(N[(p + N[Abs[p], $MachinePrecision]), $MachinePrecision] + N[(N[Abs[r], $MachinePrecision] - r), $MachinePrecision]), $MachinePrecision] * 0.5 + N[(N[(q$95$m * q$95$m), $MachinePrecision] / N[((-r) + p), $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.12 \cdot 10^{+52}:\\
        \;\;\;\;\mathsf{fma}\left(\left(p + \left|p\right|\right) + \left(\left|r\right| - r\right), 0.5, \frac{q\_m \cdot q\_m}{\left(-r\right) + p}\right)\\
        
        \mathbf{else}:\\
        \;\;\;\;-q\_m\\
        
        
        \end{array}
        \end{array}
        
        Derivation
        1. Split input into 2 regimes
        2. if q < 1.12000000000000002e52

          1. Initial program 26.4%

            \[\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. Applied rewrites52.5%

            \[\leadsto \color{blue}{\left(\left(\left|r\right| + \left|p\right|\right) - \mathsf{hypot}\left(q \cdot -2, r - p\right)\right) \cdot 0.5} \]
          3. Add Preprocessing
          4. Taylor expanded in q around 0

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

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

            if 1.12000000000000002e52 < q

            1. Initial program 36.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. Applied rewrites73.6%

              \[\leadsto \color{blue}{\left(\left(\left|r\right| + \left|p\right|\right) - \mathsf{hypot}\left(q \cdot -2, r - p\right)\right) \cdot 0.5} \]
            3. Add Preprocessing
            4. Taylor expanded in q around inf

              \[\leadsto \color{blue}{-1 \cdot q} \]
            5. Step-by-step derivation
              1. Applied rewrites72.1%

                \[\leadsto \color{blue}{-q} \]
            6. Recombined 2 regimes into one program.
            7. Final simplification49.0%

              \[\leadsto \begin{array}{l} \mathbf{if}\;q \leq 1.12 \cdot 10^{+52}:\\ \;\;\;\;\mathsf{fma}\left(\left(p + \left|p\right|\right) + \left(\left|r\right| - r\right), 0.5, \frac{q \cdot q}{\left(-r\right) + p}\right)\\ \mathbf{else}:\\ \;\;\;\;-q\\ \end{array} \]
            8. Add Preprocessing

            Alternative 4: 68.6% accurate, 7.3× 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.7 \cdot 10^{-71}:\\ \;\;\;\;\left(\left(p + \left|p\right|\right) + \left(\left|r\right| - r\right)\right) \cdot 0.5\\ \mathbf{elif}\;q\_m \leq 3.5 \cdot 10^{+19}:\\ \;\;\;\;\left(-q\_m\right) \cdot \frac{q\_m}{r - p}\\ \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.7e-71)
               (* (+ (+ p (fabs p)) (- (fabs r) r)) 0.5)
               (if (<= q_m 3.5e+19) (* (- q_m) (/ q_m (- r p))) (- 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.7e-71) {
            		tmp = ((p + fabs(p)) + (fabs(r) - r)) * 0.5;
            	} else if (q_m <= 3.5e+19) {
            		tmp = -q_m * (q_m / (r - p));
            	} 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.7d-71) then
                    tmp = ((p + abs(p)) + (abs(r) - r)) * 0.5d0
                else if (q_m <= 3.5d+19) then
                    tmp = -q_m * (q_m / (r - p))
                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.7e-71) {
            		tmp = ((p + Math.abs(p)) + (Math.abs(r) - r)) * 0.5;
            	} else if (q_m <= 3.5e+19) {
            		tmp = -q_m * (q_m / (r - p));
            	} 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.7e-71:
            		tmp = ((p + math.fabs(p)) + (math.fabs(r) - r)) * 0.5
            	elif q_m <= 3.5e+19:
            		tmp = -q_m * (q_m / (r - p))
            	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.7e-71)
            		tmp = Float64(Float64(Float64(p + abs(p)) + Float64(abs(r) - r)) * 0.5);
            	elseif (q_m <= 3.5e+19)
            		tmp = Float64(Float64(-q_m) * Float64(q_m / Float64(r - p)));
            	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.7e-71)
            		tmp = ((p + abs(p)) + (abs(r) - r)) * 0.5;
            	elseif (q_m <= 3.5e+19)
            		tmp = -q_m * (q_m / (r - p));
            	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.7e-71], N[(N[(N[(p + N[Abs[p], $MachinePrecision]), $MachinePrecision] + N[(N[Abs[r], $MachinePrecision] - r), $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision], If[LessEqual[q$95$m, 3.5e+19], N[((-q$95$m) * N[(q$95$m / N[(r - p), $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.7 \cdot 10^{-71}:\\
            \;\;\;\;\left(\left(p + \left|p\right|\right) + \left(\left|r\right| - r\right)\right) \cdot 0.5\\
            
            \mathbf{elif}\;q\_m \leq 3.5 \cdot 10^{+19}:\\
            \;\;\;\;\left(-q\_m\right) \cdot \frac{q\_m}{r - p}\\
            
            \mathbf{else}:\\
            \;\;\;\;-q\_m\\
            
            
            \end{array}
            \end{array}
            
            Derivation
            1. Split input into 3 regimes
            2. if q < 1.70000000000000002e-71

              1. Initial program 25.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. Applied rewrites52.8%

                \[\leadsto \color{blue}{\left(\left(\left|r\right| + \left|p\right|\right) - \mathsf{hypot}\left(q \cdot -2, r - p\right)\right) \cdot 0.5} \]
              3. Add Preprocessing
              4. Taylor expanded in q around 0

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

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

                if 1.70000000000000002e-71 < q < 3.5e19

                1. Initial program 27.0%

                  \[\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. Applied rewrites44.3%

                  \[\leadsto \color{blue}{\left(\left(\left|r\right| + \left|p\right|\right) - \mathsf{hypot}\left(q \cdot -2, r - p\right)\right) \cdot 0.5} \]
                3. Add Preprocessing
                4. Taylor expanded in q around 0

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

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

                    \[\leadsto -1 \cdot \color{blue}{\frac{{q}^{2}}{r - p}} \]
                  3. Step-by-step derivation
                    1. Applied rewrites59.1%

                      \[\leadsto \left(-q\right) \cdot \color{blue}{\frac{q}{r - p}} \]

                    if 3.5e19 < q

                    1. Initial program 38.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. Applied rewrites72.0%

                      \[\leadsto \color{blue}{\left(\left(\left|r\right| + \left|p\right|\right) - \mathsf{hypot}\left(q \cdot -2, r - p\right)\right) \cdot 0.5} \]
                    3. Add Preprocessing
                    4. Taylor expanded in q around inf

                      \[\leadsto \color{blue}{-1 \cdot q} \]
                    5. Step-by-step derivation
                      1. Applied rewrites70.7%

                        \[\leadsto \color{blue}{-q} \]
                    6. Recombined 3 regimes into one program.
                    7. Add Preprocessing

                    Alternative 5: 65.3% accurate, 8.1× 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 4.35 \cdot 10^{-69}:\\ \;\;\;\;\left(\left(p + \left|p\right|\right) + \left(\left|r\right| - r\right)\right) \cdot 0.5\\ \mathbf{elif}\;q\_m \leq 2.4 \cdot 10^{+17}:\\ \;\;\;\;\frac{\left(-q\_m\right) \cdot q\_m}{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 4.35e-69)
                       (* (+ (+ p (fabs p)) (- (fabs r) r)) 0.5)
                       (if (<= q_m 2.4e+17) (/ (* (- 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 <= 4.35e-69) {
                    		tmp = ((p + fabs(p)) + (fabs(r) - r)) * 0.5;
                    	} else if (q_m <= 2.4e+17) {
                    		tmp = (-q_m * q_m) / 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 <= 4.35d-69) then
                            tmp = ((p + abs(p)) + (abs(r) - r)) * 0.5d0
                        else if (q_m <= 2.4d+17) then
                            tmp = (-q_m * q_m) / 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 <= 4.35e-69) {
                    		tmp = ((p + Math.abs(p)) + (Math.abs(r) - r)) * 0.5;
                    	} else if (q_m <= 2.4e+17) {
                    		tmp = (-q_m * q_m) / 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 <= 4.35e-69:
                    		tmp = ((p + math.fabs(p)) + (math.fabs(r) - r)) * 0.5
                    	elif q_m <= 2.4e+17:
                    		tmp = (-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 <= 4.35e-69)
                    		tmp = Float64(Float64(Float64(p + abs(p)) + Float64(abs(r) - r)) * 0.5);
                    	elseif (q_m <= 2.4e+17)
                    		tmp = Float64(Float64(Float64(-q_m) * q_m) / 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 <= 4.35e-69)
                    		tmp = ((p + abs(p)) + (abs(r) - r)) * 0.5;
                    	elseif (q_m <= 2.4e+17)
                    		tmp = (-q_m * q_m) / 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, 4.35e-69], N[(N[(N[(p + N[Abs[p], $MachinePrecision]), $MachinePrecision] + N[(N[Abs[r], $MachinePrecision] - r), $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision], If[LessEqual[q$95$m, 2.4e+17], N[(N[((-q$95$m) * q$95$m), $MachinePrecision] / r), $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 4.35 \cdot 10^{-69}:\\
                    \;\;\;\;\left(\left(p + \left|p\right|\right) + \left(\left|r\right| - r\right)\right) \cdot 0.5\\
                    
                    \mathbf{elif}\;q\_m \leq 2.4 \cdot 10^{+17}:\\
                    \;\;\;\;\frac{\left(-q\_m\right) \cdot q\_m}{r}\\
                    
                    \mathbf{else}:\\
                    \;\;\;\;-q\_m\\
                    
                    
                    \end{array}
                    \end{array}
                    
                    Derivation
                    1. Split input into 3 regimes
                    2. if q < 4.34999999999999976e-69

                      1. Initial program 24.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. Applied rewrites53.0%

                        \[\leadsto \color{blue}{\left(\left(\left|r\right| + \left|p\right|\right) - \mathsf{hypot}\left(q \cdot -2, r - p\right)\right) \cdot 0.5} \]
                      3. Add Preprocessing
                      4. Taylor expanded in q around 0

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

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

                        if 4.34999999999999976e-69 < q < 2.4e17

                        1. Initial program 29.4%

                          \[\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. Applied rewrites39.3%

                          \[\leadsto \color{blue}{\left(\left(\left|r\right| + \left|p\right|\right) - \mathsf{hypot}\left(q \cdot -2, r - p\right)\right) \cdot 0.5} \]
                        3. Add Preprocessing
                        4. Taylor expanded in q around 0

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

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

                            \[\leadsto -1 \cdot \color{blue}{\frac{{q}^{2}}{r - p}} \]
                          3. Step-by-step derivation
                            1. Applied rewrites55.4%

                              \[\leadsto \left(-q\right) \cdot \color{blue}{\frac{q}{r - p}} \]
                            2. Taylor expanded in p around 0

                              \[\leadsto -1 \cdot \frac{{q}^{2}}{\color{blue}{r}} \]
                            3. Step-by-step derivation
                              1. Applied rewrites38.7%

                                \[\leadsto \frac{\left(-q\right) \cdot q}{r} \]

                              if 2.4e17 < q

                              1. Initial program 38.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. Applied rewrites72.0%

                                \[\leadsto \color{blue}{\left(\left(\left|r\right| + \left|p\right|\right) - \mathsf{hypot}\left(q \cdot -2, r - p\right)\right) \cdot 0.5} \]
                              3. Add Preprocessing
                              4. Taylor expanded in q around inf

                                \[\leadsto \color{blue}{-1 \cdot q} \]
                              5. Step-by-step derivation
                                1. Applied rewrites70.7%

                                  \[\leadsto \color{blue}{-q} \]
                              6. Recombined 3 regimes into one program.
                              7. Add Preprocessing

                              Alternative 6: 57.0% accurate, 8.1× 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 3.6 \cdot 10^{-69}:\\ \;\;\;\;\left(p + \left|p\right|\right) \cdot 0.5\\ \mathbf{elif}\;q\_m \leq 2.4 \cdot 10^{+17}:\\ \;\;\;\;\frac{\left(-q\_m\right) \cdot q\_m}{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 3.6e-69)
                                 (* (+ p (fabs p)) 0.5)
                                 (if (<= q_m 2.4e+17) (/ (* (- 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 <= 3.6e-69) {
                              		tmp = (p + fabs(p)) * 0.5;
                              	} else if (q_m <= 2.4e+17) {
                              		tmp = (-q_m * q_m) / 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 <= 3.6d-69) then
                                      tmp = (p + abs(p)) * 0.5d0
                                  else if (q_m <= 2.4d+17) then
                                      tmp = (-q_m * q_m) / 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 <= 3.6e-69) {
                              		tmp = (p + Math.abs(p)) * 0.5;
                              	} else if (q_m <= 2.4e+17) {
                              		tmp = (-q_m * q_m) / 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 <= 3.6e-69:
                              		tmp = (p + math.fabs(p)) * 0.5
                              	elif q_m <= 2.4e+17:
                              		tmp = (-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 <= 3.6e-69)
                              		tmp = Float64(Float64(p + abs(p)) * 0.5);
                              	elseif (q_m <= 2.4e+17)
                              		tmp = Float64(Float64(Float64(-q_m) * q_m) / 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 <= 3.6e-69)
                              		tmp = (p + abs(p)) * 0.5;
                              	elseif (q_m <= 2.4e+17)
                              		tmp = (-q_m * q_m) / 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, 3.6e-69], N[(N[(p + N[Abs[p], $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision], If[LessEqual[q$95$m, 2.4e+17], N[(N[((-q$95$m) * q$95$m), $MachinePrecision] / r), $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 3.6 \cdot 10^{-69}:\\
                              \;\;\;\;\left(p + \left|p\right|\right) \cdot 0.5\\
                              
                              \mathbf{elif}\;q\_m \leq 2.4 \cdot 10^{+17}:\\
                              \;\;\;\;\frac{\left(-q\_m\right) \cdot q\_m}{r}\\
                              
                              \mathbf{else}:\\
                              \;\;\;\;-q\_m\\
                              
                              
                              \end{array}
                              \end{array}
                              
                              Derivation
                              1. Split input into 3 regimes
                              2. if q < 3.60000000000000018e-69

                                1. Initial program 24.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. Applied rewrites53.0%

                                  \[\leadsto \color{blue}{\left(\left(\left|r\right| + \left|p\right|\right) - \mathsf{hypot}\left(q \cdot -2, r - p\right)\right) \cdot 0.5} \]
                                3. Add Preprocessing
                                4. Taylor expanded in q around 0

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

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

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

                                    if 3.60000000000000018e-69 < q < 2.4e17

                                    1. Initial program 29.4%

                                      \[\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. Applied rewrites39.3%

                                      \[\leadsto \color{blue}{\left(\left(\left|r\right| + \left|p\right|\right) - \mathsf{hypot}\left(q \cdot -2, r - p\right)\right) \cdot 0.5} \]
                                    3. Add Preprocessing
                                    4. Taylor expanded in q around 0

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

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

                                        \[\leadsto -1 \cdot \color{blue}{\frac{{q}^{2}}{r - p}} \]
                                      3. Step-by-step derivation
                                        1. Applied rewrites55.4%

                                          \[\leadsto \left(-q\right) \cdot \color{blue}{\frac{q}{r - p}} \]
                                        2. Taylor expanded in p around 0

                                          \[\leadsto -1 \cdot \frac{{q}^{2}}{\color{blue}{r}} \]
                                        3. Step-by-step derivation
                                          1. Applied rewrites38.7%

                                            \[\leadsto \frac{\left(-q\right) \cdot q}{r} \]

                                          if 2.4e17 < q

                                          1. Initial program 38.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. Applied rewrites72.0%

                                            \[\leadsto \color{blue}{\left(\left(\left|r\right| + \left|p\right|\right) - \mathsf{hypot}\left(q \cdot -2, r - p\right)\right) \cdot 0.5} \]
                                          3. Add Preprocessing
                                          4. Taylor expanded in q around inf

                                            \[\leadsto \color{blue}{-1 \cdot q} \]
                                          5. Step-by-step derivation
                                            1. Applied rewrites70.7%

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

                                            \[\leadsto \begin{array}{l} \mathbf{if}\;q \leq 3.6 \cdot 10^{-69}:\\ \;\;\;\;\left(p + \left|p\right|\right) \cdot 0.5\\ \mathbf{elif}\;q \leq 2.4 \cdot 10^{+17}:\\ \;\;\;\;\frac{\left(-q\right) \cdot q}{r}\\ \mathbf{else}:\\ \;\;\;\;-q\\ \end{array} \]
                                          8. Add Preprocessing

                                          Alternative 7: 56.2% 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 3.3 \cdot 10^{-66}:\\ \;\;\;\;\left(p + \left|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 3.3e-66) (* (+ p (fabs 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 <= 3.3e-66) {
                                          		tmp = (p + fabs(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 <= 3.3d-66) then
                                                  tmp = (p + abs(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 <= 3.3e-66) {
                                          		tmp = (p + Math.abs(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 <= 3.3e-66:
                                          		tmp = (p + math.fabs(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 <= 3.3e-66)
                                          		tmp = Float64(Float64(p + abs(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 <= 3.3e-66)
                                          		tmp = (p + abs(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, 3.3e-66], N[(N[(p + N[Abs[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 3.3 \cdot 10^{-66}:\\
                                          \;\;\;\;\left(p + \left|p\right|\right) \cdot 0.5\\
                                          
                                          \mathbf{else}:\\
                                          \;\;\;\;-q\_m\\
                                          
                                          
                                          \end{array}
                                          \end{array}
                                          
                                          Derivation
                                          1. Split input into 2 regimes
                                          2. if q < 3.2999999999999999e-66

                                            1. Initial program 24.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. Applied rewrites53.3%

                                              \[\leadsto \color{blue}{\left(\left(\left|r\right| + \left|p\right|\right) - \mathsf{hypot}\left(q \cdot -2, r - p\right)\right) \cdot 0.5} \]
                                            3. Add Preprocessing
                                            4. Taylor expanded in q around 0

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

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

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

                                                if 3.2999999999999999e-66 < q

                                                1. Initial program 37.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. Applied rewrites66.9%

                                                  \[\leadsto \color{blue}{\left(\left(\left|r\right| + \left|p\right|\right) - \mathsf{hypot}\left(q \cdot -2, r - p\right)\right) \cdot 0.5} \]
                                                3. Add Preprocessing
                                                4. Taylor expanded in q around inf

                                                  \[\leadsto \color{blue}{-1 \cdot q} \]
                                                5. Step-by-step derivation
                                                  1. Applied rewrites65.9%

                                                    \[\leadsto \color{blue}{-q} \]
                                                6. Recombined 2 regimes into one program.
                                                7. Final simplification36.0%

                                                  \[\leadsto \begin{array}{l} \mathbf{if}\;q \leq 3.3 \cdot 10^{-66}:\\ \;\;\;\;\left(p + \left|p\right|\right) \cdot 0.5\\ \mathbf{else}:\\ \;\;\;\;-q\\ \end{array} \]
                                                8. Add Preprocessing

                                                Alternative 8: 48.1% accurate, 20.8× 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 2.9 \cdot 10^{-66}:\\ \;\;\;\;0 \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 2.9e-66) (* 0.0 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 <= 2.9e-66) {
                                                		tmp = 0.0 * 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 <= 2.9d-66) then
                                                        tmp = 0.0d0 * 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 <= 2.9e-66) {
                                                		tmp = 0.0 * 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 <= 2.9e-66:
                                                		tmp = 0.0 * 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 <= 2.9e-66)
                                                		tmp = Float64(0.0 * 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 <= 2.9e-66)
                                                		tmp = 0.0 * 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, 2.9e-66], N[(0.0 * 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 2.9 \cdot 10^{-66}:\\
                                                \;\;\;\;0 \cdot 0.5\\
                                                
                                                \mathbf{else}:\\
                                                \;\;\;\;-q\_m\\
                                                
                                                
                                                \end{array}
                                                \end{array}
                                                
                                                Derivation
                                                1. Split input into 2 regimes
                                                2. if q < 2.90000000000000011e-66

                                                  1. Initial program 24.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. Applied rewrites53.3%

                                                    \[\leadsto \color{blue}{\left(\left(\left|r\right| + \left|p\right|\right) - \mathsf{hypot}\left(q \cdot -2, r - p\right)\right) \cdot 0.5} \]
                                                  3. Add Preprocessing
                                                  4. Taylor expanded in q around 0

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

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

                                                        \[\leadsto \left(\left(\left(p + p\right) + r\right) - \color{blue}{r}\right) \cdot 0.5 \]
                                                      2. Applied rewrites26.9%

                                                        \[\leadsto 0 \cdot 0.5 \]

                                                      if 2.90000000000000011e-66 < q

                                                      1. Initial program 37.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. Applied rewrites66.9%

                                                        \[\leadsto \color{blue}{\left(\left(\left|r\right| + \left|p\right|\right) - \mathsf{hypot}\left(q \cdot -2, r - p\right)\right) \cdot 0.5} \]
                                                      3. Add Preprocessing
                                                      4. Taylor expanded in q around inf

                                                        \[\leadsto \color{blue}{-1 \cdot q} \]
                                                      5. Step-by-step derivation
                                                        1. Applied rewrites65.9%

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

                                                      Alternative 9: 35.3% 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 28.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. Applied rewrites57.3%

                                                        \[\leadsto \color{blue}{\left(\left(\left|r\right| + \left|p\right|\right) - \mathsf{hypot}\left(q \cdot -2, r - p\right)\right) \cdot 0.5} \]
                                                      3. Add Preprocessing
                                                      4. Taylor expanded in q around inf

                                                        \[\leadsto \color{blue}{-1 \cdot q} \]
                                                      5. Step-by-step derivation
                                                        1. Applied rewrites22.9%

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

                                                        Alternative 10: 3.3% accurate, 250.0× 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 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 28.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. Applied rewrites57.3%

                                                          \[\leadsto \color{blue}{\left(\left(\left|r\right| + \left|p\right|\right) - \mathsf{hypot}\left(q \cdot -2, r - p\right)\right) \cdot 0.5} \]
                                                        3. Add Preprocessing
                                                        4. Taylor expanded in q around -inf

                                                          \[\leadsto \color{blue}{q} \]
                                                        5. Step-by-step derivation
                                                          1. Applied rewrites19.3%

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

                                                          Reproduce

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