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

Percentage Accurate: 24.5% → 57.4%
Time: 8.2s
Alternatives: 5
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)))));
}
real(8) function code(p, r, q)
    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 5 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.5% 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)))));
}
real(8) function code(p, r, q)
    real(8), intent (in) :: p
    real(8), intent (in) :: r
    real(8), intent (in) :: q
    code = (1.0d0 / 2.0d0) * ((abs(p) + abs(r)) - sqrt((((p - r) ** 2.0d0) + (4.0d0 * (q ** 2.0d0)))))
end function
public static double code(double p, double r, double q) {
	return (1.0 / 2.0) * ((Math.abs(p) + Math.abs(r)) - Math.sqrt((Math.pow((p - r), 2.0) + (4.0 * Math.pow(q, 2.0)))));
}
def code(p, r, q):
	return (1.0 / 2.0) * ((math.fabs(p) + math.fabs(r)) - math.sqrt((math.pow((p - r), 2.0) + (4.0 * math.pow(q, 2.0)))))
function code(p, r, q)
	return Float64(Float64(1.0 / 2.0) * Float64(Float64(abs(p) + abs(r)) - sqrt(Float64((Float64(p - r) ^ 2.0) + Float64(4.0 * (q ^ 2.0))))))
end
function tmp = code(p, r, q)
	tmp = (1.0 / 2.0) * ((abs(p) + abs(r)) - sqrt((((p - r) ^ 2.0) + (4.0 * (q ^ 2.0)))));
end
code[p_, r_, q_] := N[(N[(1.0 / 2.0), $MachinePrecision] * N[(N[(N[Abs[p], $MachinePrecision] + N[Abs[r], $MachinePrecision]), $MachinePrecision] - N[Sqrt[N[(N[Power[N[(p - r), $MachinePrecision], 2.0], $MachinePrecision] + N[(4.0 * N[Power[q, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

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

Alternative 1: 57.4% 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.5 \cdot 10^{-229}:\\ \;\;\;\;\left(-p\right) \cdot \left(\frac{\left(\left|r\right| - r\right) + \left|p\right|}{p} \cdot -0.5 - 0.5\right)\\ \mathbf{elif}\;q\_m \leq 8.5 \cdot 10^{-14}:\\ \;\;\;\;\left(\frac{\left|r\right| + \left(\left|p\right| + p\right)}{r} \cdot 0.5 - 0.5\right) \cdot 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.5e-229)
   (* (- p) (- (* (/ (+ (- (fabs r) r) (fabs p)) p) -0.5) 0.5))
   (if (<= q_m 8.5e-14)
     (* (- (* (/ (+ (fabs r) (+ (fabs p) p)) r) 0.5) 0.5) 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.5e-229) {
		tmp = -p * (((((fabs(r) - r) + fabs(p)) / p) * -0.5) - 0.5);
	} else if (q_m <= 8.5e-14) {
		tmp = ((((fabs(r) + (fabs(p) + p)) / r) * 0.5) - 0.5) * r;
	} else {
		tmp = -q_m;
	}
	return tmp;
}
q_m = abs(q)
NOTE: p, r, and q_m should be sorted in increasing order before calling this function.
real(8) function code(p, r, q_m)
    real(8), intent (in) :: p
    real(8), intent (in) :: r
    real(8), intent (in) :: q_m
    real(8) :: tmp
    if (q_m <= 1.5d-229) then
        tmp = -p * (((((abs(r) - r) + abs(p)) / p) * (-0.5d0)) - 0.5d0)
    else if (q_m <= 8.5d-14) then
        tmp = ((((abs(r) + (abs(p) + p)) / r) * 0.5d0) - 0.5d0) * 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.5e-229) {
		tmp = -p * (((((Math.abs(r) - r) + Math.abs(p)) / p) * -0.5) - 0.5);
	} else if (q_m <= 8.5e-14) {
		tmp = ((((Math.abs(r) + (Math.abs(p) + p)) / r) * 0.5) - 0.5) * 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.5e-229:
		tmp = -p * (((((math.fabs(r) - r) + math.fabs(p)) / p) * -0.5) - 0.5)
	elif q_m <= 8.5e-14:
		tmp = ((((math.fabs(r) + (math.fabs(p) + p)) / r) * 0.5) - 0.5) * 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.5e-229)
		tmp = Float64(Float64(-p) * Float64(Float64(Float64(Float64(Float64(abs(r) - r) + abs(p)) / p) * -0.5) - 0.5));
	elseif (q_m <= 8.5e-14)
		tmp = Float64(Float64(Float64(Float64(Float64(abs(r) + Float64(abs(p) + p)) / r) * 0.5) - 0.5) * r);
	else
		tmp = Float64(-q_m);
	end
	return tmp
end
q_m = abs(q);
p, r, q_m = num2cell(sort([p, r, q_m])){:}
function tmp_2 = code(p, r, q_m)
	tmp = 0.0;
	if (q_m <= 1.5e-229)
		tmp = -p * (((((abs(r) - r) + abs(p)) / p) * -0.5) - 0.5);
	elseif (q_m <= 8.5e-14)
		tmp = ((((abs(r) + (abs(p) + p)) / r) * 0.5) - 0.5) * 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.5e-229], N[((-p) * N[(N[(N[(N[(N[(N[Abs[r], $MachinePrecision] - r), $MachinePrecision] + N[Abs[p], $MachinePrecision]), $MachinePrecision] / p), $MachinePrecision] * -0.5), $MachinePrecision] - 0.5), $MachinePrecision]), $MachinePrecision], If[LessEqual[q$95$m, 8.5e-14], N[(N[(N[(N[(N[(N[Abs[r], $MachinePrecision] + N[(N[Abs[p], $MachinePrecision] + p), $MachinePrecision]), $MachinePrecision] / r), $MachinePrecision] * 0.5), $MachinePrecision] - 0.5), $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 1.5 \cdot 10^{-229}:\\
\;\;\;\;\left(-p\right) \cdot \left(\frac{\left(\left|r\right| - r\right) + \left|p\right|}{p} \cdot -0.5 - 0.5\right)\\

\mathbf{elif}\;q\_m \leq 8.5 \cdot 10^{-14}:\\
\;\;\;\;\left(\frac{\left|r\right| + \left(\left|p\right| + p\right)}{r} \cdot 0.5 - 0.5\right) \cdot r\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if q < 1.50000000000000001e-229

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

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

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

        \[\leadsto \color{blue}{-q} \]
    5. Applied rewrites3.6%

      \[\leadsto \color{blue}{-q} \]
    6. Taylor expanded in p around -inf

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

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

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

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

        \[\leadsto \left(\mathsf{neg}\left(p\right)\right) \cdot \left(\frac{-1}{2} \cdot \color{blue}{\left(\frac{\left|p\right|}{p} + \frac{\left|r\right| - r}{p}\right)} - \frac{1}{2}\right) \]
      5. *-lft-identityN/A

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

        \[\leadsto \left(\mathsf{neg}\left(p\right)\right) \cdot \left(\frac{-1}{2} \cdot \left(\frac{\left|p\right|}{p} + \frac{\left|r\right| - \color{blue}{\left(\mathsf{neg}\left(-1\right)\right)} \cdot r}{p}\right) - \frac{1}{2}\right) \]
      7. fp-cancel-sign-sub-invN/A

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

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

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

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

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

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

    if 1.50000000000000001e-229 < q < 8.50000000000000038e-14

    1. Initial program 20.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. Add Preprocessing
    3. Taylor expanded in r around 0

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

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

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

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

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

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

        \[\leadsto \left(\left(\left|r\right| + \left|p\right|\right) - q \cdot 2\right) \cdot 0.5 \]
      2. Taylor expanded in r around inf

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

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

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

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

      if 8.50000000000000038e-14 < q

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

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

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

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

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

    Alternative 2: 47.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 8.2 \cdot 10^{-112}:\\ \;\;\;\;{2}^{-1} \cdot \left(\left(\left|p\right| + \left|r\right|\right) - \left(r - p\right)\right)\\ \mathbf{else}:\\ \;\;\;\;-q\_m\\ \end{array} \end{array} \]
    q_m = (fabs.f64 q)
    NOTE: p, r, and q_m should be sorted in increasing order before calling this function.
    (FPCore (p r q_m)
     :precision binary64
     (if (<= q_m 8.2e-112)
       (* (pow 2.0 -1.0) (- (+ (fabs p) (fabs r)) (- 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 <= 8.2e-112) {
    		tmp = pow(2.0, -1.0) * ((fabs(p) + fabs(r)) - (r - p));
    	} else {
    		tmp = -q_m;
    	}
    	return tmp;
    }
    
    q_m = abs(q)
    NOTE: p, r, and q_m should be sorted in increasing order before calling this function.
    real(8) function code(p, r, q_m)
        real(8), intent (in) :: p
        real(8), intent (in) :: r
        real(8), intent (in) :: q_m
        real(8) :: tmp
        if (q_m <= 8.2d-112) then
            tmp = (2.0d0 ** (-1.0d0)) * ((abs(p) + abs(r)) - (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 <= 8.2e-112) {
    		tmp = Math.pow(2.0, -1.0) * ((Math.abs(p) + Math.abs(r)) - (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 <= 8.2e-112:
    		tmp = math.pow(2.0, -1.0) * ((math.fabs(p) + math.fabs(r)) - (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 <= 8.2e-112)
    		tmp = Float64((2.0 ^ -1.0) * Float64(Float64(abs(p) + abs(r)) - 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 <= 8.2e-112)
    		tmp = (2.0 ^ -1.0) * ((abs(p) + abs(r)) - (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, 8.2e-112], N[(N[Power[2.0, -1.0], $MachinePrecision] * N[(N[(N[Abs[p], $MachinePrecision] + N[Abs[r], $MachinePrecision]), $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 8.2 \cdot 10^{-112}:\\
    \;\;\;\;{2}^{-1} \cdot \left(\left(\left|p\right| + \left|r\right|\right) - \left(r - p\right)\right)\\
    
    \mathbf{else}:\\
    \;\;\;\;-q\_m\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 2 regimes
    2. if q < 8.19999999999999991e-112

      1. Initial program 18.9%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{1}{2} \cdot \left(\left(\left|p\right| + \left|r\right|\right) - \color{blue}{\left(-p\right) \cdot \left(1 - \frac{r}{p}\right)}\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. Applied rewrites12.9%

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

        if 8.19999999999999991e-112 < q

        1. Initial program 22.2%

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

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

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

            \[\leadsto \color{blue}{-q} \]
        5. Applied rewrites62.6%

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

        \[\leadsto \begin{array}{l} \mathbf{if}\;q \leq 8.2 \cdot 10^{-112}:\\ \;\;\;\;{2}^{-1} \cdot \left(\left(\left|p\right| + \left|r\right|\right) - \left(r - p\right)\right)\\ \mathbf{else}:\\ \;\;\;\;-q\\ \end{array} \]
      10. Add Preprocessing

      Alternative 3: 57.4% accurate, 6.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 8.5 \cdot 10^{-14}:\\ \;\;\;\;\left(\frac{\left|r\right| + \left(\left|p\right| + p\right)}{r} \cdot 0.5 - 0.5\right) \cdot 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 8.5e-14)
         (* (- (* (/ (+ (fabs r) (+ (fabs p) p)) r) 0.5) 0.5) 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 <= 8.5e-14) {
      		tmp = ((((fabs(r) + (fabs(p) + p)) / r) * 0.5) - 0.5) * r;
      	} else {
      		tmp = -q_m;
      	}
      	return tmp;
      }
      
      q_m = abs(q)
      NOTE: p, r, and q_m should be sorted in increasing order before calling this function.
      real(8) function code(p, r, q_m)
          real(8), intent (in) :: p
          real(8), intent (in) :: r
          real(8), intent (in) :: q_m
          real(8) :: tmp
          if (q_m <= 8.5d-14) then
              tmp = ((((abs(r) + (abs(p) + p)) / r) * 0.5d0) - 0.5d0) * 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 <= 8.5e-14) {
      		tmp = ((((Math.abs(r) + (Math.abs(p) + p)) / r) * 0.5) - 0.5) * 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 <= 8.5e-14:
      		tmp = ((((math.fabs(r) + (math.fabs(p) + p)) / r) * 0.5) - 0.5) * 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 <= 8.5e-14)
      		tmp = Float64(Float64(Float64(Float64(Float64(abs(r) + Float64(abs(p) + p)) / r) * 0.5) - 0.5) * 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 <= 8.5e-14)
      		tmp = ((((abs(r) + (abs(p) + p)) / r) * 0.5) - 0.5) * 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, 8.5e-14], N[(N[(N[(N[(N[(N[Abs[r], $MachinePrecision] + N[(N[Abs[p], $MachinePrecision] + p), $MachinePrecision]), $MachinePrecision] / r), $MachinePrecision] * 0.5), $MachinePrecision] - 0.5), $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 8.5 \cdot 10^{-14}:\\
      \;\;\;\;\left(\frac{\left|r\right| + \left(\left|p\right| + p\right)}{r} \cdot 0.5 - 0.5\right) \cdot r\\
      
      \mathbf{else}:\\
      \;\;\;\;-q\_m\\
      
      
      \end{array}
      \end{array}
      
      Derivation
      1. Split input into 2 regimes
      2. if q < 8.50000000000000038e-14

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

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

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

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

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

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

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

            \[\leadsto \left(\left(\left|r\right| + \left|p\right|\right) - q \cdot 2\right) \cdot 0.5 \]
          2. Taylor expanded in r around inf

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

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

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

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

          if 8.50000000000000038e-14 < q

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

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

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

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

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

        Alternative 4: 47.5% accurate, 16.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 8.2 \cdot 10^{-112}:\\ \;\;\;\;\left(0.5 - 0.5\right) \cdot 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 8.2e-112) (* (- 0.5 0.5) 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 <= 8.2e-112) {
        		tmp = (0.5 - 0.5) * r;
        	} else {
        		tmp = -q_m;
        	}
        	return tmp;
        }
        
        q_m = abs(q)
        NOTE: p, r, and q_m should be sorted in increasing order before calling this function.
        real(8) function code(p, r, q_m)
            real(8), intent (in) :: p
            real(8), intent (in) :: r
            real(8), intent (in) :: q_m
            real(8) :: tmp
            if (q_m <= 8.2d-112) then
                tmp = (0.5d0 - 0.5d0) * 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 <= 8.2e-112) {
        		tmp = (0.5 - 0.5) * 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 <= 8.2e-112:
        		tmp = (0.5 - 0.5) * 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 <= 8.2e-112)
        		tmp = Float64(Float64(0.5 - 0.5) * 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 <= 8.2e-112)
        		tmp = (0.5 - 0.5) * 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, 8.2e-112], N[(N[(0.5 - 0.5), $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 8.2 \cdot 10^{-112}:\\
        \;\;\;\;\left(0.5 - 0.5\right) \cdot r\\
        
        \mathbf{else}:\\
        \;\;\;\;-q\_m\\
        
        
        \end{array}
        \end{array}
        
        Derivation
        1. Split input into 2 regimes
        2. if q < 8.19999999999999991e-112

          1. Initial program 18.9%

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

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

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

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

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

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

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

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

              if 8.19999999999999991e-112 < q

              1. Initial program 22.2%

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

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

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

                  \[\leadsto \color{blue}{-q} \]
              5. Applied rewrites62.6%

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

            Alternative 5: 35.2% 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 = abs(q)
            NOTE: p, r, and q_m should be sorted in increasing order before calling this function.
            real(8) function code(p, r, q_m)
                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 19.9%

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

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

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

                \[\leadsto \color{blue}{-q} \]
            5. Applied rewrites22.9%

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

            Reproduce

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