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

Percentage Accurate: 23.6% → 67.5%
Time: 8.5s
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: 23.6% 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: 67.5% accurate, 1.8× speedup?

\[\begin{array}{l} q_m = \left|q\right| \\ [p, r, q_m] = \mathsf{sort}([p, r, q_m])\\ \\ \begin{array}{l} \mathbf{if}\;{q\_m}^{2} \leq 2 \cdot 10^{+22}:\\ \;\;\;\;\left(\left(\left|p\right| + p\right) - \left(r - \left|r\right|\right)\right) \cdot \frac{1}{2}\\ \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 (<= (pow q_m 2.0) 2e+22)
   (* (- (+ (fabs p) p) (- r (fabs r))) (/ 1.0 2.0))
   (- q_m)))
q_m = fabs(q);
assert(p < r && r < q_m);
double code(double p, double r, double q_m) {
	double tmp;
	if (pow(q_m, 2.0) <= 2e+22) {
		tmp = ((fabs(p) + p) - (r - fabs(r))) * (1.0 / 2.0);
	} 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 ** 2.0d0) <= 2d+22) then
        tmp = ((abs(p) + p) - (r - abs(r))) * (1.0d0 / 2.0d0)
    else
        tmp = -q_m
    end if
    code = tmp
end function
q_m = Math.abs(q);
assert p < r && r < q_m;
public static double code(double p, double r, double q_m) {
	double tmp;
	if (Math.pow(q_m, 2.0) <= 2e+22) {
		tmp = ((Math.abs(p) + p) - (r - Math.abs(r))) * (1.0 / 2.0);
	} else {
		tmp = -q_m;
	}
	return tmp;
}
q_m = math.fabs(q)
[p, r, q_m] = sort([p, r, q_m])
def code(p, r, q_m):
	tmp = 0
	if math.pow(q_m, 2.0) <= 2e+22:
		tmp = ((math.fabs(p) + p) - (r - math.fabs(r))) * (1.0 / 2.0)
	else:
		tmp = -q_m
	return tmp
q_m = abs(q)
p, r, q_m = sort([p, r, q_m])
function code(p, r, q_m)
	tmp = 0.0
	if ((q_m ^ 2.0) <= 2e+22)
		tmp = Float64(Float64(Float64(abs(p) + p) - Float64(r - abs(r))) * Float64(1.0 / 2.0));
	else
		tmp = Float64(-q_m);
	end
	return tmp
end
q_m = abs(q);
p, r, q_m = num2cell(sort([p, r, q_m])){:}
function tmp_2 = code(p, r, q_m)
	tmp = 0.0;
	if ((q_m ^ 2.0) <= 2e+22)
		tmp = ((abs(p) + p) - (r - abs(r))) * (1.0 / 2.0);
	else
		tmp = -q_m;
	end
	tmp_2 = tmp;
end
q_m = N[Abs[q], $MachinePrecision]
NOTE: p, r, and q_m should be sorted in increasing order before calling this function.
code[p_, r_, q$95$m_] := If[LessEqual[N[Power[q$95$m, 2.0], $MachinePrecision], 2e+22], N[(N[(N[(N[Abs[p], $MachinePrecision] + p), $MachinePrecision] - N[(r - N[Abs[r], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(1.0 / 2.0), $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}^{2} \leq 2 \cdot 10^{+22}:\\
\;\;\;\;\left(\left(\left|p\right| + p\right) - \left(r - \left|r\right|\right)\right) \cdot \frac{1}{2}\\

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


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

    1. Initial program 22.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 \color{blue}{\left(r \cdot \left(\left(\frac{\left|p\right|}{r} + \frac{\left|r\right|}{r}\right) - \left(1 + -1 \cdot \frac{p}{r}\right)\right)\right)} \]
    4. Step-by-step derivation
      1. *-commutativeN/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      if 2e22 < (pow.f64 q #s(literal 2 binary64))

      1. Initial program 34.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 \frac{1}{2} \cdot \color{blue}{\left(-2 \cdot q\right)} \]
      4. Step-by-step derivation
        1. lower-*.f6434.5

          \[\leadsto \frac{1}{2} \cdot \color{blue}{\left(-2 \cdot q\right)} \]
      5. Applied rewrites34.5%

        \[\leadsto \frac{1}{2} \cdot \color{blue}{\left(-2 \cdot q\right)} \]
      6. Taylor expanded in q around inf

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

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

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

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

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

    Alternative 2: 57.7% accurate, 1.9× speedup?

    \[\begin{array}{l} q_m = \left|q\right| \\ [p, r, q_m] = \mathsf{sort}([p, r, q_m])\\ \\ \begin{array}{l} \mathbf{if}\;{q\_m}^{2} \leq 2000000000000:\\ \;\;\;\;\mathsf{fma}\left(0, p, \left|r\right| - r\right) \cdot \frac{1}{2}\\ \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 (<= (pow q_m 2.0) 2000000000000.0)
       (* (fma 0.0 p (- (fabs r) r)) (/ 1.0 2.0))
       (- q_m)))
    q_m = fabs(q);
    assert(p < r && r < q_m);
    double code(double p, double r, double q_m) {
    	double tmp;
    	if (pow(q_m, 2.0) <= 2000000000000.0) {
    		tmp = fma(0.0, p, (fabs(r) - r)) * (1.0 / 2.0);
    	} else {
    		tmp = -q_m;
    	}
    	return tmp;
    }
    
    q_m = abs(q)
    p, r, q_m = sort([p, r, q_m])
    function code(p, r, q_m)
    	tmp = 0.0
    	if ((q_m ^ 2.0) <= 2000000000000.0)
    		tmp = Float64(fma(0.0, p, Float64(abs(r) - r)) * Float64(1.0 / 2.0));
    	else
    		tmp = Float64(-q_m);
    	end
    	return tmp
    end
    
    q_m = N[Abs[q], $MachinePrecision]
    NOTE: p, r, and q_m should be sorted in increasing order before calling this function.
    code[p_, r_, q$95$m_] := If[LessEqual[N[Power[q$95$m, 2.0], $MachinePrecision], 2000000000000.0], N[(N[(0.0 * p + N[(N[Abs[r], $MachinePrecision] - r), $MachinePrecision]), $MachinePrecision] * N[(1.0 / 2.0), $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}^{2} \leq 2000000000000:\\
    \;\;\;\;\mathsf{fma}\left(0, p, \left|r\right| - r\right) \cdot \frac{1}{2}\\
    
    \mathbf{else}:\\
    \;\;\;\;-q\_m\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 2 regimes
    2. if (pow.f64 q #s(literal 2 binary64)) < 2e12

      1. Initial program 22.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            if 2e12 < (pow.f64 q #s(literal 2 binary64))

            1. Initial program 33.8%

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

              \[\leadsto \frac{1}{2} \cdot \color{blue}{\left(-2 \cdot q\right)} \]
            4. Step-by-step derivation
              1. lower-*.f6434.1

                \[\leadsto \frac{1}{2} \cdot \color{blue}{\left(-2 \cdot q\right)} \]
            5. Applied rewrites34.1%

              \[\leadsto \frac{1}{2} \cdot \color{blue}{\left(-2 \cdot q\right)} \]
            6. Taylor expanded in q around inf

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

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

                \[\leadsto \color{blue}{-q} \]
            8. Applied rewrites34.1%

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

            \[\leadsto \begin{array}{l} \mathbf{if}\;{q}^{2} \leq 2000000000000:\\ \;\;\;\;\mathsf{fma}\left(0, p, \left|r\right| - r\right) \cdot \frac{1}{2}\\ \mathbf{else}:\\ \;\;\;\;-q\\ \end{array} \]
          5. Add Preprocessing

          Alternative 3: 57.3% accurate, 1.9× speedup?

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

            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 r around inf

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                if 1e-99 < (pow.f64 q #s(literal 2 binary64))

                1. Initial program 33.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 \color{blue}{\left(-2 \cdot q\right)} \]
                4. Step-by-step derivation
                  1. lower-*.f6431.5

                    \[\leadsto \frac{1}{2} \cdot \color{blue}{\left(-2 \cdot q\right)} \]
                5. Applied rewrites31.5%

                  \[\leadsto \frac{1}{2} \cdot \color{blue}{\left(-2 \cdot q\right)} \]
                6. Taylor expanded in q around inf

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

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

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

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

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

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

                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 r around inf

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                        \[\leadsto \color{blue}{\left(\left(p + \left|p\right|\right) + \left(r - r\right)\right) \cdot 0.5} \]
                    3. Applied rewrites45.3%

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

                    if 1e-99 < (pow.f64 q #s(literal 2 binary64))

                    1. Initial program 33.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 \color{blue}{\left(-2 \cdot q\right)} \]
                    4. Step-by-step derivation
                      1. lower-*.f6431.5

                        \[\leadsto \frac{1}{2} \cdot \color{blue}{\left(-2 \cdot q\right)} \]
                    5. Applied rewrites31.5%

                      \[\leadsto \frac{1}{2} \cdot \color{blue}{\left(-2 \cdot q\right)} \]
                    6. Taylor expanded in q around inf

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

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

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

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

                  Alternative 5: 35.5% 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 28.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 \frac{1}{2} \cdot \color{blue}{\left(-2 \cdot q\right)} \]
                  4. Step-by-step derivation
                    1. lower-*.f6420.2

                      \[\leadsto \frac{1}{2} \cdot \color{blue}{\left(-2 \cdot q\right)} \]
                  5. Applied rewrites20.2%

                    \[\leadsto \frac{1}{2} \cdot \color{blue}{\left(-2 \cdot q\right)} \]
                  6. Taylor expanded in q around inf

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

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

                      \[\leadsto \color{blue}{-q} \]
                  8. Applied rewrites20.2%

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

                  Reproduce

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