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

Percentage Accurate: 44.3% → 82.5%
Time: 4.6s
Alternatives: 7
Speedup: 35.6×

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}

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 7 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: 44.3% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \frac{1}{2} \cdot \left(\left(\left|p\right| + \left|r\right|\right) + \sqrt{{\left(p - r\right)}^{2} + 4 \cdot {q}^{2}}\right) \end{array} \]
(FPCore (p r q)
 :precision binary64
 (*
  (/ 1.0 2.0)
  (+ (+ (fabs p) (fabs r)) (sqrt (+ (pow (- p r) 2.0) (* 4.0 (pow q 2.0)))))))
double code(double p, double r, double q) {
	return (1.0 / 2.0) * ((fabs(p) + fabs(r)) + sqrt((pow((p - r), 2.0) + (4.0 * pow(q, 2.0)))));
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

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

real(8) function code(p, r, q)
use fmin_fmax_functions
    real(8), intent (in) :: p
    real(8), intent (in) :: r
    real(8), intent (in) :: q
    code = (1.0d0 / 2.0d0) * ((abs(p) + abs(r)) + sqrt((((p - r) ** 2.0d0) + (4.0d0 * (q ** 2.0d0)))))
end function
public static double code(double p, double r, double q) {
	return (1.0 / 2.0) * ((Math.abs(p) + Math.abs(r)) + Math.sqrt((Math.pow((p - r), 2.0) + (4.0 * Math.pow(q, 2.0)))));
}
def code(p, r, q):
	return (1.0 / 2.0) * ((math.fabs(p) + math.fabs(r)) + math.sqrt((math.pow((p - r), 2.0) + (4.0 * math.pow(q, 2.0)))))
function code(p, r, q)
	return Float64(Float64(1.0 / 2.0) * Float64(Float64(abs(p) + abs(r)) + sqrt(Float64((Float64(p - r) ^ 2.0) + Float64(4.0 * (q ^ 2.0))))))
end
function tmp = code(p, r, q)
	tmp = (1.0 / 2.0) * ((abs(p) + abs(r)) + sqrt((((p - r) ^ 2.0) + (4.0 * (q ^ 2.0)))));
end
code[p_, r_, q_] := N[(N[(1.0 / 2.0), $MachinePrecision] * N[(N[(N[Abs[p], $MachinePrecision] + N[Abs[r], $MachinePrecision]), $MachinePrecision] + N[Sqrt[N[(N[Power[N[(p - r), $MachinePrecision], 2.0], $MachinePrecision] + N[(4.0 * N[Power[q, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

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

Alternative 1: 82.5% 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} t_0 := \left|r\right| + \left|p\right|\\ \mathbf{if}\;4 \cdot {q\_m}^{2} \leq 5 \cdot 10^{+235}:\\ \;\;\;\;\left(t\_0 + \left(\left(-p\right) + r\right)\right) \cdot 0.5\\ \mathbf{else}:\\ \;\;\;\;\left(q\_m \cdot 2 + t\_0\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
 (let* ((t_0 (+ (fabs r) (fabs p))))
   (if (<= (* 4.0 (pow q_m 2.0)) 5e+235)
     (* (+ t_0 (+ (- p) r)) 0.5)
     (* (+ (* q_m 2.0) t_0) 0.5))))
q_m = fabs(q);
assert(p < r && r < q_m);
double code(double p, double r, double q_m) {
	double t_0 = fabs(r) + fabs(p);
	double tmp;
	if ((4.0 * pow(q_m, 2.0)) <= 5e+235) {
		tmp = (t_0 + (-p + r)) * 0.5;
	} else {
		tmp = ((q_m * 2.0) + t_0) * 0.5;
	}
	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) :: t_0
    real(8) :: tmp
    t_0 = abs(r) + abs(p)
    if ((4.0d0 * (q_m ** 2.0d0)) <= 5d+235) then
        tmp = (t_0 + (-p + r)) * 0.5d0
    else
        tmp = ((q_m * 2.0d0) + t_0) * 0.5d0
    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 t_0 = Math.abs(r) + Math.abs(p);
	double tmp;
	if ((4.0 * Math.pow(q_m, 2.0)) <= 5e+235) {
		tmp = (t_0 + (-p + r)) * 0.5;
	} else {
		tmp = ((q_m * 2.0) + t_0) * 0.5;
	}
	return tmp;
}
q_m = math.fabs(q)
[p, r, q_m] = sort([p, r, q_m])
def code(p, r, q_m):
	t_0 = math.fabs(r) + math.fabs(p)
	tmp = 0
	if (4.0 * math.pow(q_m, 2.0)) <= 5e+235:
		tmp = (t_0 + (-p + r)) * 0.5
	else:
		tmp = ((q_m * 2.0) + t_0) * 0.5
	return tmp
q_m = abs(q)
p, r, q_m = sort([p, r, q_m])
function code(p, r, q_m)
	t_0 = Float64(abs(r) + abs(p))
	tmp = 0.0
	if (Float64(4.0 * (q_m ^ 2.0)) <= 5e+235)
		tmp = Float64(Float64(t_0 + Float64(Float64(-p) + r)) * 0.5);
	else
		tmp = Float64(Float64(Float64(q_m * 2.0) + t_0) * 0.5);
	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)
	t_0 = abs(r) + abs(p);
	tmp = 0.0;
	if ((4.0 * (q_m ^ 2.0)) <= 5e+235)
		tmp = (t_0 + (-p + r)) * 0.5;
	else
		tmp = ((q_m * 2.0) + t_0) * 0.5;
	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_] := Block[{t$95$0 = N[(N[Abs[r], $MachinePrecision] + N[Abs[p], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(4.0 * N[Power[q$95$m, 2.0], $MachinePrecision]), $MachinePrecision], 5e+235], N[(N[(t$95$0 + N[((-p) + r), $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision], N[(N[(N[(q$95$m * 2.0), $MachinePrecision] + t$95$0), $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}
t_0 := \left|r\right| + \left|p\right|\\
\mathbf{if}\;4 \cdot {q\_m}^{2} \leq 5 \cdot 10^{+235}:\\
\;\;\;\;\left(t\_0 + \left(\left(-p\right) + r\right)\right) \cdot 0.5\\

\mathbf{else}:\\
\;\;\;\;\left(q\_m \cdot 2 + t\_0\right) \cdot 0.5\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 #s(literal 4 binary64) (pow.f64 q #s(literal 2 binary64))) < 5.00000000000000027e235

    1. Initial program 56.9%

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

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

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

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

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

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

        \[\leadsto \frac{1}{2} \cdot \left(\left(\left|p\right| + \left|r\right|\right) + \mathsf{fma}\left(\frac{p}{r}, -1, 1\right) \cdot r\right) \]
      6. lower-/.f6474.6

        \[\leadsto \frac{1}{2} \cdot \left(\left(\left|p\right| + \left|r\right|\right) + \mathsf{fma}\left(\frac{p}{r}, -1, 1\right) \cdot r\right) \]
    5. Applied rewrites74.6%

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

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

        \[\leadsto \frac{1}{2} \cdot \left(\left(\left|p\right| + \left|r\right|\right) + \left(r + \left(\mathsf{neg}\left(p\right)\right)\right)\right) \]
      2. lift-neg.f64N/A

        \[\leadsto \frac{1}{2} \cdot \left(\left(\left|p\right| + \left|r\right|\right) + \left(r + \left(-p\right)\right)\right) \]
      3. +-commutativeN/A

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

        \[\leadsto \frac{1}{2} \cdot \left(\left(\left|p\right| + \left|r\right|\right) + \left(\left(\mathsf{neg}\left(p\right)\right) + r\right)\right) \]
      5. mul-1-negN/A

        \[\leadsto \frac{1}{2} \cdot \left(\left(\left|p\right| + \left|r\right|\right) + \left(-1 \cdot p + r\right)\right) \]
      6. lower-fma.f6485.4

        \[\leadsto \frac{1}{2} \cdot \left(\left(\left|p\right| + \left|r\right|\right) + \mathsf{fma}\left(-1, p, r\right)\right) \]
    8. Applied rewrites85.4%

      \[\leadsto \frac{1}{2} \cdot \left(\left(\left|p\right| + \left|r\right|\right) + \mathsf{fma}\left(-1, \color{blue}{p}, r\right)\right) \]
    9. Step-by-step derivation
      1. lift-*.f64N/A

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

        \[\leadsto \color{blue}{\frac{1}{2}} \cdot \left(\left(\left|p\right| + \left|r\right|\right) + \mathsf{fma}\left(-1, p, r\right)\right) \]
      3. *-commutativeN/A

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

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

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

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

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

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

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

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

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

        \[\leadsto \left(\left(\left|r\right| + \left|p\right|\right) + \mathsf{fma}\left(-1, p, r\right)\right) \cdot \color{blue}{0.5} \]
    10. Applied rewrites85.4%

      \[\leadsto \color{blue}{\left(\left(\left|r\right| + \left|p\right|\right) + \mathsf{fma}\left(-1, p, r\right)\right) \cdot 0.5} \]
    11. Step-by-step derivation
      1. lift-fma.f64N/A

        \[\leadsto \left(\left(\left|r\right| + \left|p\right|\right) + \left(-1 \cdot p + r\right)\right) \cdot \frac{1}{2} \]
      2. mul-1-negN/A

        \[\leadsto \left(\left(\left|r\right| + \left|p\right|\right) + \left(\left(\mathsf{neg}\left(p\right)\right) + r\right)\right) \cdot \frac{1}{2} \]
      3. lift-neg.f64N/A

        \[\leadsto \left(\left(\left|r\right| + \left|p\right|\right) + \left(\left(-p\right) + r\right)\right) \cdot \frac{1}{2} \]
      4. lower-+.f6485.4

        \[\leadsto \left(\left(\left|r\right| + \left|p\right|\right) + \left(\left(-p\right) + r\right)\right) \cdot 0.5 \]
    12. Applied rewrites85.4%

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

    if 5.00000000000000027e235 < (*.f64 #s(literal 4 binary64) (pow.f64 q #s(literal 2 binary64)))

    1. Initial program 16.9%

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\left(q \cdot 2 + \left(\left|r\right| + \left|p\right|\right)\right) \cdot 0.5} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 2: 58.9% 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}\;4 \cdot {q\_m}^{2} \leq 5 \cdot 10^{+99}:\\ \;\;\;\;\left(r + \left(\left|r\right| + \left|p\right|\right)\right) \cdot 0.5\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(r, 0.5, q\_m\right)\\ \end{array} \end{array} \]
q_m = (fabs.f64 q)
NOTE: p, r, and q_m should be sorted in increasing order before calling this function.
(FPCore (p r q_m)
 :precision binary64
 (if (<= (* 4.0 (pow q_m 2.0)) 5e+99)
   (* (+ r (+ (fabs r) (fabs p))) 0.5)
   (fma r 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 ((4.0 * pow(q_m, 2.0)) <= 5e+99) {
		tmp = (r + (fabs(r) + fabs(p))) * 0.5;
	} else {
		tmp = fma(r, 0.5, q_m);
	}
	return tmp;
}
q_m = abs(q)
p, r, q_m = sort([p, r, q_m])
function code(p, r, q_m)
	tmp = 0.0
	if (Float64(4.0 * (q_m ^ 2.0)) <= 5e+99)
		tmp = Float64(Float64(r + Float64(abs(r) + abs(p))) * 0.5);
	else
		tmp = fma(r, 0.5, 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[N[(4.0 * N[Power[q$95$m, 2.0], $MachinePrecision]), $MachinePrecision], 5e+99], N[(N[(r + N[(N[Abs[r], $MachinePrecision] + N[Abs[p], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision], N[(r * 0.5 + q$95$m), $MachinePrecision]]
\begin{array}{l}
q_m = \left|q\right|
\\
[p, r, q_m] = \mathsf{sort}([p, r, q_m])\\
\\
\begin{array}{l}
\mathbf{if}\;4 \cdot {q\_m}^{2} \leq 5 \cdot 10^{+99}:\\
\;\;\;\;\left(r + \left(\left|r\right| + \left|p\right|\right)\right) \cdot 0.5\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(r, 0.5, q\_m\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 #s(literal 4 binary64) (pow.f64 q #s(literal 2 binary64))) < 5.00000000000000008e99

    1. Initial program 56.6%

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

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

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

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

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

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

        \[\leadsto \frac{1}{2} \cdot \left(\left(\left|p\right| + \left|r\right|\right) + \mathsf{fma}\left(\frac{p}{r}, -1, 1\right) \cdot r\right) \]
      6. lower-/.f6478.5

        \[\leadsto \frac{1}{2} \cdot \left(\left(\left|p\right| + \left|r\right|\right) + \mathsf{fma}\left(\frac{p}{r}, -1, 1\right) \cdot r\right) \]
    5. Applied rewrites78.5%

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

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

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

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

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

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

          \[\leadsto \color{blue}{\left(\left(\left|p\right| + \left|r\right|\right) + r\right) \cdot \frac{1}{2}} \]
      3. Applied rewrites52.9%

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

      if 5.00000000000000008e99 < (*.f64 #s(literal 4 binary64) (pow.f64 q #s(literal 2 binary64)))

      1. Initial program 27.3%

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

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

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

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

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

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

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

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

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

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

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

          \[\leadsto \mathsf{fma}\left(r + p, \frac{1}{\color{blue}{2}}, q\right) \]
        6. lift-+.f64N/A

          \[\leadsto \mathsf{fma}\left(r + p, \frac{1}{2}, q\right) \]
        7. metadata-eval66.1

          \[\leadsto \mathsf{fma}\left(r + p, 0.5, q\right) \]
      8. Applied rewrites66.1%

        \[\leadsto \mathsf{fma}\left(r + p, \color{blue}{0.5}, q\right) \]
      9. Taylor expanded in p around 0

        \[\leadsto \mathsf{fma}\left(r, \frac{1}{2}, q\right) \]
      10. Step-by-step derivation
        1. Applied rewrites67.2%

          \[\leadsto \mathsf{fma}\left(r, 0.5, q\right) \]
      11. Recombined 2 regimes into one program.
      12. Add Preprocessing

      Alternative 3: 65.1% accurate, 7.6× speedup?

      \[\begin{array}{l} q_m = \left|q\right| \\ [p, r, q_m] = \mathsf{sort}([p, r, q_m])\\ \\ \begin{array}{l} t_0 := \left|r\right| + \left|p\right|\\ \mathbf{if}\;r \leq 1.8 \cdot 10^{-255}:\\ \;\;\;\;\left(\left(-p\right) + t\_0\right) \cdot 0.5\\ \mathbf{elif}\;r \leq 1.16 \cdot 10^{+70}:\\ \;\;\;\;\left(q\_m \cdot 2 + t\_0\right) \cdot 0.5\\ \mathbf{else}:\\ \;\;\;\;r\\ \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
       (let* ((t_0 (+ (fabs r) (fabs p))))
         (if (<= r 1.8e-255)
           (* (+ (- p) t_0) 0.5)
           (if (<= r 1.16e+70) (* (+ (* q_m 2.0) t_0) 0.5) r))))
      q_m = fabs(q);
      assert(p < r && r < q_m);
      double code(double p, double r, double q_m) {
      	double t_0 = fabs(r) + fabs(p);
      	double tmp;
      	if (r <= 1.8e-255) {
      		tmp = (-p + t_0) * 0.5;
      	} else if (r <= 1.16e+70) {
      		tmp = ((q_m * 2.0) + t_0) * 0.5;
      	} else {
      		tmp = r;
      	}
      	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) :: t_0
          real(8) :: tmp
          t_0 = abs(r) + abs(p)
          if (r <= 1.8d-255) then
              tmp = (-p + t_0) * 0.5d0
          else if (r <= 1.16d+70) then
              tmp = ((q_m * 2.0d0) + t_0) * 0.5d0
          else
              tmp = r
          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 t_0 = Math.abs(r) + Math.abs(p);
      	double tmp;
      	if (r <= 1.8e-255) {
      		tmp = (-p + t_0) * 0.5;
      	} else if (r <= 1.16e+70) {
      		tmp = ((q_m * 2.0) + t_0) * 0.5;
      	} else {
      		tmp = r;
      	}
      	return tmp;
      }
      
      q_m = math.fabs(q)
      [p, r, q_m] = sort([p, r, q_m])
      def code(p, r, q_m):
      	t_0 = math.fabs(r) + math.fabs(p)
      	tmp = 0
      	if r <= 1.8e-255:
      		tmp = (-p + t_0) * 0.5
      	elif r <= 1.16e+70:
      		tmp = ((q_m * 2.0) + t_0) * 0.5
      	else:
      		tmp = r
      	return tmp
      
      q_m = abs(q)
      p, r, q_m = sort([p, r, q_m])
      function code(p, r, q_m)
      	t_0 = Float64(abs(r) + abs(p))
      	tmp = 0.0
      	if (r <= 1.8e-255)
      		tmp = Float64(Float64(Float64(-p) + t_0) * 0.5);
      	elseif (r <= 1.16e+70)
      		tmp = Float64(Float64(Float64(q_m * 2.0) + t_0) * 0.5);
      	else
      		tmp = r;
      	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)
      	t_0 = abs(r) + abs(p);
      	tmp = 0.0;
      	if (r <= 1.8e-255)
      		tmp = (-p + t_0) * 0.5;
      	elseif (r <= 1.16e+70)
      		tmp = ((q_m * 2.0) + t_0) * 0.5;
      	else
      		tmp = r;
      	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_] := Block[{t$95$0 = N[(N[Abs[r], $MachinePrecision] + N[Abs[p], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[r, 1.8e-255], N[(N[((-p) + t$95$0), $MachinePrecision] * 0.5), $MachinePrecision], If[LessEqual[r, 1.16e+70], N[(N[(N[(q$95$m * 2.0), $MachinePrecision] + t$95$0), $MachinePrecision] * 0.5), $MachinePrecision], r]]]
      
      \begin{array}{l}
      q_m = \left|q\right|
      \\
      [p, r, q_m] = \mathsf{sort}([p, r, q_m])\\
      \\
      \begin{array}{l}
      t_0 := \left|r\right| + \left|p\right|\\
      \mathbf{if}\;r \leq 1.8 \cdot 10^{-255}:\\
      \;\;\;\;\left(\left(-p\right) + t\_0\right) \cdot 0.5\\
      
      \mathbf{elif}\;r \leq 1.16 \cdot 10^{+70}:\\
      \;\;\;\;\left(q\_m \cdot 2 + t\_0\right) \cdot 0.5\\
      
      \mathbf{else}:\\
      \;\;\;\;r\\
      
      
      \end{array}
      \end{array}
      
      Derivation
      1. Split input into 3 regimes
      2. if r < 1.8000000000000001e-255

        1. Initial program 46.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. Add Preprocessing
        3. Taylor expanded in p around -inf

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

            \[\leadsto \frac{1}{2} \cdot \left(\left(\left|p\right| + \left|r\right|\right) + \left(\mathsf{neg}\left(p\right)\right)\right) \]
          2. lower-neg.f6464.2

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

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

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

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

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

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

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

        if 1.8000000000000001e-255 < r < 1.1599999999999999e70

        1. Initial program 61.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. Add Preprocessing
        3. Taylor expanded in q around inf

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

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

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

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

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

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

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

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

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

        if 1.1599999999999999e70 < r

        1. Initial program 26.8%

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

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

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

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

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

          \[\leadsto \color{blue}{\left(\left(\sqrt{\mathsf{fma}\left(q \cdot q, 4, r \cdot r\right)} + r\right) + p\right) \cdot 0.5} \]
        6. Taylor expanded in r around inf

          \[\leadsto r \]
        7. Step-by-step derivation
          1. Applied rewrites74.5%

            \[\leadsto r \]
        8. Recombined 3 regimes into one program.
        9. Add Preprocessing

        Alternative 4: 63.6% accurate, 10.4× speedup?

        \[\begin{array}{l} q_m = \left|q\right| \\ [p, r, q_m] = \mathsf{sort}([p, r, q_m])\\ \\ \begin{array}{l} \mathbf{if}\;r \leq 1.88 \cdot 10^{-255}:\\ \;\;\;\;\left(\left(-p\right) + \left(\left|r\right| + \left|p\right|\right)\right) \cdot 0.5\\ \mathbf{elif}\;r \leq 1.16 \cdot 10^{+70}:\\ \;\;\;\;\mathsf{fma}\left(r, 0.5, q\_m\right)\\ \mathbf{else}:\\ \;\;\;\;r\\ \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 (<= r 1.88e-255)
           (* (+ (- p) (+ (fabs r) (fabs p))) 0.5)
           (if (<= r 1.16e+70) (fma r 0.5 q_m) r)))
        q_m = fabs(q);
        assert(p < r && r < q_m);
        double code(double p, double r, double q_m) {
        	double tmp;
        	if (r <= 1.88e-255) {
        		tmp = (-p + (fabs(r) + fabs(p))) * 0.5;
        	} else if (r <= 1.16e+70) {
        		tmp = fma(r, 0.5, q_m);
        	} else {
        		tmp = r;
        	}
        	return tmp;
        }
        
        q_m = abs(q)
        p, r, q_m = sort([p, r, q_m])
        function code(p, r, q_m)
        	tmp = 0.0
        	if (r <= 1.88e-255)
        		tmp = Float64(Float64(Float64(-p) + Float64(abs(r) + abs(p))) * 0.5);
        	elseif (r <= 1.16e+70)
        		tmp = fma(r, 0.5, q_m);
        	else
        		tmp = r;
        	end
        	return tmp
        end
        
        q_m = N[Abs[q], $MachinePrecision]
        NOTE: p, r, and q_m should be sorted in increasing order before calling this function.
        code[p_, r_, q$95$m_] := If[LessEqual[r, 1.88e-255], N[(N[((-p) + N[(N[Abs[r], $MachinePrecision] + N[Abs[p], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision], If[LessEqual[r, 1.16e+70], N[(r * 0.5 + q$95$m), $MachinePrecision], r]]
        
        \begin{array}{l}
        q_m = \left|q\right|
        \\
        [p, r, q_m] = \mathsf{sort}([p, r, q_m])\\
        \\
        \begin{array}{l}
        \mathbf{if}\;r \leq 1.88 \cdot 10^{-255}:\\
        \;\;\;\;\left(\left(-p\right) + \left(\left|r\right| + \left|p\right|\right)\right) \cdot 0.5\\
        
        \mathbf{elif}\;r \leq 1.16 \cdot 10^{+70}:\\
        \;\;\;\;\mathsf{fma}\left(r, 0.5, q\_m\right)\\
        
        \mathbf{else}:\\
        \;\;\;\;r\\
        
        
        \end{array}
        \end{array}
        
        Derivation
        1. Split input into 3 regimes
        2. if r < 1.87999999999999993e-255

          1. Initial program 46.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. Add Preprocessing
          3. Taylor expanded in p around -inf

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

              \[\leadsto \frac{1}{2} \cdot \left(\left(\left|p\right| + \left|r\right|\right) + \left(\mathsf{neg}\left(p\right)\right)\right) \]
            2. lower-neg.f6464.2

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

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

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

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

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

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

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

          if 1.87999999999999993e-255 < r < 1.1599999999999999e70

          1. Initial program 61.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. Add Preprocessing
          3. Taylor expanded in q around inf

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

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

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

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

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

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

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

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

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

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

              \[\leadsto \mathsf{fma}\left(r + p, \frac{1}{\color{blue}{2}}, q\right) \]
            6. lift-+.f64N/A

              \[\leadsto \mathsf{fma}\left(r + p, \frac{1}{2}, q\right) \]
            7. metadata-eval50.3

              \[\leadsto \mathsf{fma}\left(r + p, 0.5, q\right) \]
          8. Applied rewrites50.3%

            \[\leadsto \mathsf{fma}\left(r + p, \color{blue}{0.5}, q\right) \]
          9. Taylor expanded in p around 0

            \[\leadsto \mathsf{fma}\left(r, \frac{1}{2}, q\right) \]
          10. Step-by-step derivation
            1. Applied rewrites51.7%

              \[\leadsto \mathsf{fma}\left(r, 0.5, q\right) \]

            if 1.1599999999999999e70 < r

            1. Initial program 26.8%

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

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

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

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

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

              \[\leadsto \color{blue}{\left(\left(\sqrt{\mathsf{fma}\left(q \cdot q, 4, r \cdot r\right)} + r\right) + p\right) \cdot 0.5} \]
            6. Taylor expanded in r around inf

              \[\leadsto r \]
            7. Step-by-step derivation
              1. Applied rewrites74.5%

                \[\leadsto r \]
            8. Recombined 3 regimes into one program.
            9. Add Preprocessing

            Alternative 5: 55.0% accurate, 19.2× speedup?

            \[\begin{array}{l} q_m = \left|q\right| \\ [p, r, q_m] = \mathsf{sort}([p, r, q_m])\\ \\ \begin{array}{l} \mathbf{if}\;q\_m \leq 1.35 \cdot 10^{+41}:\\ \;\;\;\;r\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(r, 0.5, q\_m\right)\\ \end{array} \end{array} \]
            q_m = (fabs.f64 q)
            NOTE: p, r, and q_m should be sorted in increasing order before calling this function.
            (FPCore (p r q_m) :precision binary64 (if (<= q_m 1.35e+41) r (fma r 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 <= 1.35e+41) {
            		tmp = r;
            	} else {
            		tmp = fma(r, 0.5, 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.35e+41)
            		tmp = r;
            	else
            		tmp = fma(r, 0.5, 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.35e+41], r, N[(r * 0.5 + q$95$m), $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 1.35 \cdot 10^{+41}:\\
            \;\;\;\;r\\
            
            \mathbf{else}:\\
            \;\;\;\;\mathsf{fma}\left(r, 0.5, q\_m\right)\\
            
            
            \end{array}
            \end{array}
            
            Derivation
            1. Split input into 2 regimes
            2. if q < 1.35e41

              1. Initial program 56.7%

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

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

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

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

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

                \[\leadsto \color{blue}{\left(\left(\sqrt{\mathsf{fma}\left(q \cdot q, 4, r \cdot r\right)} + r\right) + p\right) \cdot 0.5} \]
              6. Taylor expanded in r around inf

                \[\leadsto r \]
              7. Step-by-step derivation
                1. Applied rewrites46.4%

                  \[\leadsto r \]

                if 1.35e41 < q

                1. Initial program 28.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. Add Preprocessing
                3. Taylor expanded in q around inf

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

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

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

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

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

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

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

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

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

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

                    \[\leadsto \mathsf{fma}\left(r + p, \frac{1}{\color{blue}{2}}, q\right) \]
                  6. lift-+.f64N/A

                    \[\leadsto \mathsf{fma}\left(r + p, \frac{1}{2}, q\right) \]
                  7. metadata-eval65.3

                    \[\leadsto \mathsf{fma}\left(r + p, 0.5, q\right) \]
                8. Applied rewrites65.3%

                  \[\leadsto \mathsf{fma}\left(r + p, \color{blue}{0.5}, q\right) \]
                9. Taylor expanded in p around 0

                  \[\leadsto \mathsf{fma}\left(r, \frac{1}{2}, q\right) \]
                10. Step-by-step derivation
                  1. Applied rewrites66.5%

                    \[\leadsto \mathsf{fma}\left(r, 0.5, q\right) \]
                11. Recombined 2 regimes into one program.
                12. Add Preprocessing

                Alternative 6: 53.8% accurate, 35.6× speedup?

                \[\begin{array}{l} q_m = \left|q\right| \\ [p, r, q_m] = \mathsf{sort}([p, r, q_m])\\ \\ \begin{array}{l} \mathbf{if}\;q\_m \leq 1.35 \cdot 10^{+41}:\\ \;\;\;\;r\\ \mathbf{else}:\\ \;\;\;\;q\_m\\ \end{array} \end{array} \]
                q_m = (fabs.f64 q)
                NOTE: p, r, and q_m should be sorted in increasing order before calling this function.
                (FPCore (p r q_m) :precision binary64 (if (<= q_m 1.35e+41) r q_m))
                q_m = fabs(q);
                assert(p < r && r < q_m);
                double code(double p, double r, double q_m) {
                	double tmp;
                	if (q_m <= 1.35e+41) {
                		tmp = r;
                	} else {
                		tmp = q_m;
                	}
                	return tmp;
                }
                
                q_m =     private
                NOTE: p, r, and q_m should be sorted in increasing order before calling this function.
                module fmin_fmax_functions
                    implicit none
                    private
                    public fmax
                    public fmin
                
                    interface fmax
                        module procedure fmax88
                        module procedure fmax44
                        module procedure fmax84
                        module procedure fmax48
                    end interface
                    interface fmin
                        module procedure fmin88
                        module procedure fmin44
                        module procedure fmin84
                        module procedure fmin48
                    end interface
                contains
                    real(8) function fmax88(x, y) result (res)
                        real(8), intent (in) :: x
                        real(8), intent (in) :: y
                        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
                    end function
                    real(4) function fmax44(x, y) result (res)
                        real(4), intent (in) :: x
                        real(4), intent (in) :: y
                        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
                    end function
                    real(8) function fmax84(x, y) result(res)
                        real(8), intent (in) :: x
                        real(4), intent (in) :: y
                        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
                    end function
                    real(8) function fmax48(x, y) result(res)
                        real(4), intent (in) :: x
                        real(8), intent (in) :: y
                        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
                    end function
                    real(8) function fmin88(x, y) result (res)
                        real(8), intent (in) :: x
                        real(8), intent (in) :: y
                        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
                    end function
                    real(4) function fmin44(x, y) result (res)
                        real(4), intent (in) :: x
                        real(4), intent (in) :: y
                        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
                    end function
                    real(8) function fmin84(x, y) result(res)
                        real(8), intent (in) :: x
                        real(4), intent (in) :: y
                        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
                    end function
                    real(8) function fmin48(x, y) result(res)
                        real(4), intent (in) :: x
                        real(8), intent (in) :: y
                        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
                    end function
                end module
                
                real(8) function code(p, r, q_m)
                use fmin_fmax_functions
                    real(8), intent (in) :: p
                    real(8), intent (in) :: r
                    real(8), intent (in) :: q_m
                    real(8) :: tmp
                    if (q_m <= 1.35d+41) then
                        tmp = r
                    else
                        tmp = q_m
                    end if
                    code = tmp
                end function
                
                q_m = Math.abs(q);
                assert p < r && r < q_m;
                public static double code(double p, double r, double q_m) {
                	double tmp;
                	if (q_m <= 1.35e+41) {
                		tmp = r;
                	} else {
                		tmp = q_m;
                	}
                	return tmp;
                }
                
                q_m = math.fabs(q)
                [p, r, q_m] = sort([p, r, q_m])
                def code(p, r, q_m):
                	tmp = 0
                	if q_m <= 1.35e+41:
                		tmp = r
                	else:
                		tmp = q_m
                	return tmp
                
                q_m = abs(q)
                p, r, q_m = sort([p, r, q_m])
                function code(p, r, q_m)
                	tmp = 0.0
                	if (q_m <= 1.35e+41)
                		tmp = r;
                	else
                		tmp = 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.35e+41)
                		tmp = r;
                	else
                		tmp = q_m;
                	end
                	tmp_2 = tmp;
                end
                
                q_m = N[Abs[q], $MachinePrecision]
                NOTE: p, r, and q_m should be sorted in increasing order before calling this function.
                code[p_, r_, q$95$m_] := If[LessEqual[q$95$m, 1.35e+41], r, 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.35 \cdot 10^{+41}:\\
                \;\;\;\;r\\
                
                \mathbf{else}:\\
                \;\;\;\;q\_m\\
                
                
                \end{array}
                \end{array}
                
                Derivation
                1. Split input into 2 regimes
                2. if q < 1.35e41

                  1. Initial program 56.7%

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

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

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

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

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

                    \[\leadsto \color{blue}{\left(\left(\sqrt{\mathsf{fma}\left(q \cdot q, 4, r \cdot r\right)} + r\right) + p\right) \cdot 0.5} \]
                  6. Taylor expanded in r around inf

                    \[\leadsto r \]
                  7. Step-by-step derivation
                    1. Applied rewrites46.4%

                      \[\leadsto r \]

                    if 1.35e41 < q

                    1. Initial program 28.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. Add Preprocessing
                    3. Taylor expanded in q around inf

                      \[\leadsto \color{blue}{q} \]
                    4. Step-by-step derivation
                      1. Applied rewrites63.7%

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

                    Alternative 7: 35.1% 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 44.3%

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

                      \[\leadsto \color{blue}{q} \]
                    4. Step-by-step derivation
                      1. Applied rewrites35.1%

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

                      Reproduce

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