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

Percentage Accurate: 23.7% → 48.8%
Time: 9.6s
Alternatives: 9
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 9 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.7% 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: 48.8% accurate, 3.2× 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(\left|p\right| + p\right) + \left|r\right|\\ \mathbf{if}\;r \leq -2.15 \cdot 10^{-175}:\\ \;\;\;\;\mathsf{fma}\left(t\_0, \frac{0.5}{r}, -0.5\right) \cdot r\\ \mathbf{elif}\;r \leq 4.25 \cdot 10^{+40}:\\ \;\;\;\;-q\_m\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(-1, \frac{q\_m}{r} \cdot \frac{q\_m}{r}, \mathsf{fma}\left(\frac{t\_0}{r}, 0.5, -0.5\right)\right) \cdot 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 p) p) (fabs r))))
   (if (<= r -2.15e-175)
     (* (fma t_0 (/ 0.5 r) -0.5) r)
     (if (<= r 4.25e+40)
       (- q_m)
       (* (fma -1.0 (* (/ q_m r) (/ q_m r)) (fma (/ t_0 r) 0.5 -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(p) + p) + fabs(r);
	double tmp;
	if (r <= -2.15e-175) {
		tmp = fma(t_0, (0.5 / r), -0.5) * r;
	} else if (r <= 4.25e+40) {
		tmp = -q_m;
	} else {
		tmp = fma(-1.0, ((q_m / r) * (q_m / r)), fma((t_0 / r), 0.5, -0.5)) * 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(Float64(abs(p) + p) + abs(r))
	tmp = 0.0
	if (r <= -2.15e-175)
		tmp = Float64(fma(t_0, Float64(0.5 / r), -0.5) * r);
	elseif (r <= 4.25e+40)
		tmp = Float64(-q_m);
	else
		tmp = Float64(fma(-1.0, Float64(Float64(q_m / r) * Float64(q_m / r)), fma(Float64(t_0 / r), 0.5, -0.5)) * 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_] := Block[{t$95$0 = N[(N[(N[Abs[p], $MachinePrecision] + p), $MachinePrecision] + N[Abs[r], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[r, -2.15e-175], N[(N[(t$95$0 * N[(0.5 / r), $MachinePrecision] + -0.5), $MachinePrecision] * r), $MachinePrecision], If[LessEqual[r, 4.25e+40], (-q$95$m), N[(N[(-1.0 * N[(N[(q$95$m / r), $MachinePrecision] * N[(q$95$m / r), $MachinePrecision]), $MachinePrecision] + N[(N[(t$95$0 / r), $MachinePrecision] * 0.5 + -0.5), $MachinePrecision]), $MachinePrecision] * r), $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(\left|p\right| + p\right) + \left|r\right|\\
\mathbf{if}\;r \leq -2.15 \cdot 10^{-175}:\\
\;\;\;\;\mathsf{fma}\left(t\_0, \frac{0.5}{r}, -0.5\right) \cdot r\\

\mathbf{elif}\;r \leq 4.25 \cdot 10^{+40}:\\
\;\;\;\;-q\_m\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(-1, \frac{q\_m}{r} \cdot \frac{q\_m}{r}, \mathsf{fma}\left(\frac{t\_0}{r}, 0.5, -0.5\right)\right) \cdot r\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if r < -2.14999999999999999e-175

    1. Initial program 21.3%

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

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

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

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

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

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

      if -2.14999999999999999e-175 < r < 4.24999999999999998e40

      1. Initial program 31.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.f6424.5

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

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

      if 4.24999999999999998e40 < r

      1. Initial program 8.7%

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

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

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

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

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

            \[\leadsto \mathsf{fma}\left(-1, \frac{q}{r} \cdot \frac{q}{r}, \mathsf{fma}\left(\frac{\left(\left|p\right| + p\right) + \left|r\right|}{r}, 0.5, -0.5\right)\right) \cdot r \]
        3. Recombined 3 regimes into one program.
        4. Add Preprocessing

        Alternative 2: 46.5% accurate, 1.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}^{2} \leq 0:\\ \;\;\;\;\frac{\left(-q\_m\right) \cdot q\_m}{q\_m}\\ \mathbf{elif}\;{q\_m}^{2} \leq 5 \cdot 10^{-54}:\\ \;\;\;\;\mathsf{fma}\left(\left(\left|p\right| + p\right) + \left|r\right|, \frac{0.5}{r}, -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 (<= (pow q_m 2.0) 0.0)
           (/ (* (- q_m) q_m) q_m)
           (if (<= (pow q_m 2.0) 5e-54)
             (* (fma (+ (+ (fabs p) p) (fabs r)) (/ 0.5 r) -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 (pow(q_m, 2.0) <= 0.0) {
        		tmp = (-q_m * q_m) / q_m;
        	} else if (pow(q_m, 2.0) <= 5e-54) {
        		tmp = fma(((fabs(p) + p) + fabs(r)), (0.5 / r), -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 ^ 2.0) <= 0.0)
        		tmp = Float64(Float64(Float64(-q_m) * q_m) / q_m);
        	elseif ((q_m ^ 2.0) <= 5e-54)
        		tmp = Float64(fma(Float64(Float64(abs(p) + p) + abs(r)), Float64(0.5 / r), -0.5) * r);
        	else
        		tmp = Float64(-q_m);
        	end
        	return tmp
        end
        
        q_m = N[Abs[q], $MachinePrecision]
        NOTE: p, r, and q_m should be sorted in increasing order before calling this function.
        code[p_, r_, q$95$m_] := If[LessEqual[N[Power[q$95$m, 2.0], $MachinePrecision], 0.0], N[(N[((-q$95$m) * q$95$m), $MachinePrecision] / q$95$m), $MachinePrecision], If[LessEqual[N[Power[q$95$m, 2.0], $MachinePrecision], 5e-54], N[(N[(N[(N[(N[Abs[p], $MachinePrecision] + p), $MachinePrecision] + N[Abs[r], $MachinePrecision]), $MachinePrecision] * N[(0.5 / r), $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}^{2} \leq 0:\\
        \;\;\;\;\frac{\left(-q\_m\right) \cdot q\_m}{q\_m}\\
        
        \mathbf{elif}\;{q\_m}^{2} \leq 5 \cdot 10^{-54}:\\
        \;\;\;\;\mathsf{fma}\left(\left(\left|p\right| + p\right) + \left|r\right|, \frac{0.5}{r}, -0.5\right) \cdot r\\
        
        \mathbf{else}:\\
        \;\;\;\;-q\_m\\
        
        
        \end{array}
        \end{array}
        
        Derivation
        1. Split input into 3 regimes
        2. if (pow.f64 q #s(literal 2 binary64)) < 0.0

          1. Initial program 31.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.f649.3

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

            \[\leadsto \color{blue}{-q} \]
          6. Step-by-step derivation
            1. Applied rewrites50.8%

              \[\leadsto \frac{0 - q \cdot q}{\color{blue}{0 + q}} \]

            if 0.0 < (pow.f64 q #s(literal 2 binary64)) < 5.00000000000000015e-54

            1. Initial program 15.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 rewrites10.2%

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

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

              if 5.00000000000000015e-54 < (pow.f64 q #s(literal 2 binary64))

              1. Initial program 22.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.f6428.1

                  \[\leadsto \color{blue}{-q} \]
              5. Applied rewrites28.1%

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

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

            Alternative 3: 46.5% accurate, 1.0× 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(-q\_m\right) \cdot q\_m\\ \mathbf{if}\;{q\_m}^{2} \leq 5 \cdot 10^{-266}:\\ \;\;\;\;\frac{t\_0}{q\_m}\\ \mathbf{elif}\;{q\_m}^{2} \leq 10^{-36}:\\ \;\;\;\;\frac{t\_0 \cdot \left(r + p\right)}{r \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
             (let* ((t_0 (* (- q_m) q_m)))
               (if (<= (pow q_m 2.0) 5e-266)
                 (/ t_0 q_m)
                 (if (<= (pow q_m 2.0) 1e-36) (/ (* t_0 (+ r p)) (* r r)) (- q_m)))))
            q_m = fabs(q);
            assert(p < r && r < q_m);
            double code(double p, double r, double q_m) {
            	double t_0 = -q_m * q_m;
            	double tmp;
            	if (pow(q_m, 2.0) <= 5e-266) {
            		tmp = t_0 / q_m;
            	} else if (pow(q_m, 2.0) <= 1e-36) {
            		tmp = (t_0 * (r + p)) / (r * 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) :: t_0
                real(8) :: tmp
                t_0 = -q_m * q_m
                if ((q_m ** 2.0d0) <= 5d-266) then
                    tmp = t_0 / q_m
                else if ((q_m ** 2.0d0) <= 1d-36) then
                    tmp = (t_0 * (r + p)) / (r * 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 t_0 = -q_m * q_m;
            	double tmp;
            	if (Math.pow(q_m, 2.0) <= 5e-266) {
            		tmp = t_0 / q_m;
            	} else if (Math.pow(q_m, 2.0) <= 1e-36) {
            		tmp = (t_0 * (r + p)) / (r * 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):
            	t_0 = -q_m * q_m
            	tmp = 0
            	if math.pow(q_m, 2.0) <= 5e-266:
            		tmp = t_0 / q_m
            	elif math.pow(q_m, 2.0) <= 1e-36:
            		tmp = (t_0 * (r + p)) / (r * 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)
            	t_0 = Float64(Float64(-q_m) * q_m)
            	tmp = 0.0
            	if ((q_m ^ 2.0) <= 5e-266)
            		tmp = Float64(t_0 / q_m);
            	elseif ((q_m ^ 2.0) <= 1e-36)
            		tmp = Float64(Float64(t_0 * Float64(r + p)) / Float64(r * 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)
            	t_0 = -q_m * q_m;
            	tmp = 0.0;
            	if ((q_m ^ 2.0) <= 5e-266)
            		tmp = t_0 / q_m;
            	elseif ((q_m ^ 2.0) <= 1e-36)
            		tmp = (t_0 * (r + p)) / (r * 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_] := Block[{t$95$0 = N[((-q$95$m) * q$95$m), $MachinePrecision]}, If[LessEqual[N[Power[q$95$m, 2.0], $MachinePrecision], 5e-266], N[(t$95$0 / q$95$m), $MachinePrecision], If[LessEqual[N[Power[q$95$m, 2.0], $MachinePrecision], 1e-36], N[(N[(t$95$0 * N[(r + p), $MachinePrecision]), $MachinePrecision] / N[(r * r), $MachinePrecision]), $MachinePrecision], (-q$95$m)]]]
            
            \begin{array}{l}
            q_m = \left|q\right|
            \\
            [p, r, q_m] = \mathsf{sort}([p, r, q_m])\\
            \\
            \begin{array}{l}
            t_0 := \left(-q\_m\right) \cdot q\_m\\
            \mathbf{if}\;{q\_m}^{2} \leq 5 \cdot 10^{-266}:\\
            \;\;\;\;\frac{t\_0}{q\_m}\\
            
            \mathbf{elif}\;{q\_m}^{2} \leq 10^{-36}:\\
            \;\;\;\;\frac{t\_0 \cdot \left(r + p\right)}{r \cdot r}\\
            
            \mathbf{else}:\\
            \;\;\;\;-q\_m\\
            
            
            \end{array}
            \end{array}
            
            Derivation
            1. Split input into 3 regimes
            2. if (pow.f64 q #s(literal 2 binary64)) < 4.99999999999999992e-266

              1. Initial program 29.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}{-1 \cdot q} \]
              4. Step-by-step derivation
                1. mul-1-negN/A

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

                  \[\leadsto \color{blue}{-q} \]
              5. Applied rewrites11.1%

                \[\leadsto \color{blue}{-q} \]
              6. Step-by-step derivation
                1. Applied rewrites42.8%

                  \[\leadsto \frac{0 - q \cdot q}{\color{blue}{0 + q}} \]

                if 4.99999999999999992e-266 < (pow.f64 q #s(literal 2 binary64)) < 9.9999999999999994e-37

                1. Initial program 15.1%

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

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

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

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

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

                  if 9.9999999999999994e-37 < (pow.f64 q #s(literal 2 binary64))

                  1. Initial program 22.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.f6429.8

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

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

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

                Alternative 4: 45.4% accurate, 1.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 5 \cdot 10^{-266}:\\ \;\;\;\;\frac{\left(-q\_m\right) \cdot q\_m}{q\_m}\\ \mathbf{elif}\;{q\_m}^{2} \leq 10^{-52}:\\ \;\;\;\;\mathsf{fma}\left(\left(p + \left|r\right|\right) + \left|p\right|, 0.5, -0.5 \cdot r\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 (<= (pow q_m 2.0) 5e-266)
                   (/ (* (- q_m) q_m) q_m)
                   (if (<= (pow q_m 2.0) 1e-52)
                     (fma (+ (+ p (fabs r)) (fabs p)) 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 (pow(q_m, 2.0) <= 5e-266) {
                		tmp = (-q_m * q_m) / q_m;
                	} else if (pow(q_m, 2.0) <= 1e-52) {
                		tmp = fma(((p + fabs(r)) + fabs(p)), 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 ^ 2.0) <= 5e-266)
                		tmp = Float64(Float64(Float64(-q_m) * q_m) / q_m);
                	elseif ((q_m ^ 2.0) <= 1e-52)
                		tmp = fma(Float64(Float64(p + abs(r)) + abs(p)), 0.5, Float64(-0.5 * r));
                	else
                		tmp = Float64(-q_m);
                	end
                	return tmp
                end
                
                q_m = N[Abs[q], $MachinePrecision]
                NOTE: p, r, and q_m should be sorted in increasing order before calling this function.
                code[p_, r_, q$95$m_] := If[LessEqual[N[Power[q$95$m, 2.0], $MachinePrecision], 5e-266], N[(N[((-q$95$m) * q$95$m), $MachinePrecision] / q$95$m), $MachinePrecision], If[LessEqual[N[Power[q$95$m, 2.0], $MachinePrecision], 1e-52], N[(N[(N[(p + N[Abs[r], $MachinePrecision]), $MachinePrecision] + N[Abs[p], $MachinePrecision]), $MachinePrecision] * 0.5 + N[(-0.5 * r), $MachinePrecision]), $MachinePrecision], (-q$95$m)]]
                
                \begin{array}{l}
                q_m = \left|q\right|
                \\
                [p, r, q_m] = \mathsf{sort}([p, r, q_m])\\
                \\
                \begin{array}{l}
                \mathbf{if}\;{q\_m}^{2} \leq 5 \cdot 10^{-266}:\\
                \;\;\;\;\frac{\left(-q\_m\right) \cdot q\_m}{q\_m}\\
                
                \mathbf{elif}\;{q\_m}^{2} \leq 10^{-52}:\\
                \;\;\;\;\mathsf{fma}\left(\left(p + \left|r\right|\right) + \left|p\right|, 0.5, -0.5 \cdot r\right)\\
                
                \mathbf{else}:\\
                \;\;\;\;-q\_m\\
                
                
                \end{array}
                \end{array}
                
                Derivation
                1. Split input into 3 regimes
                2. if (pow.f64 q #s(literal 2 binary64)) < 4.99999999999999992e-266

                  1. Initial program 29.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}{-1 \cdot q} \]
                  4. Step-by-step derivation
                    1. mul-1-negN/A

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

                      \[\leadsto \color{blue}{-q} \]
                  5. Applied rewrites11.1%

                    \[\leadsto \color{blue}{-q} \]
                  6. Step-by-step derivation
                    1. Applied rewrites42.8%

                      \[\leadsto \frac{0 - q \cdot q}{\color{blue}{0 + q}} \]

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

                    1. Initial program 13.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 \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 rewrites11.8%

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

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

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

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

                      1. Initial program 22.5%

                        \[\frac{1}{2} \cdot \left(\left(\left|p\right| + \left|r\right|\right) - \sqrt{{\left(p - r\right)}^{2} + 4 \cdot {q}^{2}}\right) \]
                      2. Add Preprocessing
                      3. Taylor expanded in 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.f6428.2

                          \[\leadsto \color{blue}{-q} \]
                      5. Applied rewrites28.2%

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

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

                    Alternative 5: 47.2% accurate, 3.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}\;r \leq -2.15 \cdot 10^{-175}:\\ \;\;\;\;\mathsf{fma}\left(\left(\left|p\right| + p\right) + \left|r\right|, \frac{0.5}{r}, -0.5\right) \cdot r\\ \mathbf{elif}\;r \leq 2.05 \cdot 10^{+134}:\\ \;\;\;\;-q\_m\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(-1, \frac{q\_m}{r} \cdot \frac{q\_m}{r}, \mathsf{fma}\left(\frac{\left|r\right| + \left|p\right|}{r}, 0.5, -0.5\right)\right) \cdot 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 -2.15e-175)
                       (* (fma (+ (+ (fabs p) p) (fabs r)) (/ 0.5 r) -0.5) r)
                       (if (<= r 2.05e+134)
                         (- q_m)
                         (*
                          (fma
                           -1.0
                           (* (/ q_m r) (/ q_m r))
                           (fma (/ (+ (fabs r) (fabs p)) r) 0.5 -0.5))
                          r))))
                    q_m = fabs(q);
                    assert(p < r && r < q_m);
                    double code(double p, double r, double q_m) {
                    	double tmp;
                    	if (r <= -2.15e-175) {
                    		tmp = fma(((fabs(p) + p) + fabs(r)), (0.5 / r), -0.5) * r;
                    	} else if (r <= 2.05e+134) {
                    		tmp = -q_m;
                    	} else {
                    		tmp = fma(-1.0, ((q_m / r) * (q_m / r)), fma(((fabs(r) + fabs(p)) / r), 0.5, -0.5)) * 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 <= -2.15e-175)
                    		tmp = Float64(fma(Float64(Float64(abs(p) + p) + abs(r)), Float64(0.5 / r), -0.5) * r);
                    	elseif (r <= 2.05e+134)
                    		tmp = Float64(-q_m);
                    	else
                    		tmp = Float64(fma(-1.0, Float64(Float64(q_m / r) * Float64(q_m / r)), fma(Float64(Float64(abs(r) + abs(p)) / r), 0.5, -0.5)) * 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, -2.15e-175], N[(N[(N[(N[(N[Abs[p], $MachinePrecision] + p), $MachinePrecision] + N[Abs[r], $MachinePrecision]), $MachinePrecision] * N[(0.5 / r), $MachinePrecision] + -0.5), $MachinePrecision] * r), $MachinePrecision], If[LessEqual[r, 2.05e+134], (-q$95$m), N[(N[(-1.0 * N[(N[(q$95$m / r), $MachinePrecision] * N[(q$95$m / r), $MachinePrecision]), $MachinePrecision] + N[(N[(N[(N[Abs[r], $MachinePrecision] + N[Abs[p], $MachinePrecision]), $MachinePrecision] / r), $MachinePrecision] * 0.5 + -0.5), $MachinePrecision]), $MachinePrecision] * r), $MachinePrecision]]]
                    
                    \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 -2.15 \cdot 10^{-175}:\\
                    \;\;\;\;\mathsf{fma}\left(\left(\left|p\right| + p\right) + \left|r\right|, \frac{0.5}{r}, -0.5\right) \cdot r\\
                    
                    \mathbf{elif}\;r \leq 2.05 \cdot 10^{+134}:\\
                    \;\;\;\;-q\_m\\
                    
                    \mathbf{else}:\\
                    \;\;\;\;\mathsf{fma}\left(-1, \frac{q\_m}{r} \cdot \frac{q\_m}{r}, \mathsf{fma}\left(\frac{\left|r\right| + \left|p\right|}{r}, 0.5, -0.5\right)\right) \cdot r\\
                    
                    
                    \end{array}
                    \end{array}
                    
                    Derivation
                    1. Split input into 3 regimes
                    2. if r < -2.14999999999999999e-175

                      1. Initial program 21.3%

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

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

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

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

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

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

                        if -2.14999999999999999e-175 < r < 2.0500000000000002e134

                        1. Initial program 29.6%

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

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

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

                            \[\leadsto \color{blue}{-q} \]
                        5. Applied rewrites23.2%

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

                        if 2.0500000000000002e134 < r

                        1. Initial program 5.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 \color{blue}{r \cdot \left(\left(-1 \cdot \frac{p \cdot {q}^{2}}{{r}^{3}} + \left(-1 \cdot \frac{{q}^{2}}{{r}^{2}} + \frac{1}{2} \cdot \frac{\left(\left|p\right| + \left|r\right|\right) - -1 \cdot p}{r}\right)\right) - \frac{1}{2}\right)} \]
                        4. Applied rewrites42.9%

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

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

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

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

                              \[\leadsto \mathsf{fma}\left(-1, \frac{q}{r} \cdot \frac{q}{r}, \mathsf{fma}\left(\frac{\left|r\right| + \left|p\right|}{r}, 0.5, -0.5\right)\right) \cdot r \]
                          4. Recombined 3 regimes into one program.
                          5. Add Preprocessing

                          Alternative 6: 48.3% accurate, 5.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}\;r \leq -2.15 \cdot 10^{-175}:\\ \;\;\;\;\mathsf{fma}\left(\left(\left|p\right| + p\right) + \left|r\right|, \frac{0.5}{r}, -0.5\right) \cdot r\\ \mathbf{elif}\;r \leq 4.25 \cdot 10^{+40}:\\ \;\;\;\;-q\_m\\ \mathbf{else}:\\ \;\;\;\;\left(\left(-q\_m\right) \cdot q\_m\right) \cdot \frac{\frac{p}{r} + 1}{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 -2.15e-175)
                             (* (fma (+ (+ (fabs p) p) (fabs r)) (/ 0.5 r) -0.5) r)
                             (if (<= r 4.25e+40) (- q_m) (* (* (- q_m) q_m) (/ (+ (/ p r) 1.0) r)))))
                          q_m = fabs(q);
                          assert(p < r && r < q_m);
                          double code(double p, double r, double q_m) {
                          	double tmp;
                          	if (r <= -2.15e-175) {
                          		tmp = fma(((fabs(p) + p) + fabs(r)), (0.5 / r), -0.5) * r;
                          	} else if (r <= 4.25e+40) {
                          		tmp = -q_m;
                          	} else {
                          		tmp = (-q_m * q_m) * (((p / r) + 1.0) / 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 <= -2.15e-175)
                          		tmp = Float64(fma(Float64(Float64(abs(p) + p) + abs(r)), Float64(0.5 / r), -0.5) * r);
                          	elseif (r <= 4.25e+40)
                          		tmp = Float64(-q_m);
                          	else
                          		tmp = Float64(Float64(Float64(-q_m) * q_m) * Float64(Float64(Float64(p / r) + 1.0) / 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, -2.15e-175], N[(N[(N[(N[(N[Abs[p], $MachinePrecision] + p), $MachinePrecision] + N[Abs[r], $MachinePrecision]), $MachinePrecision] * N[(0.5 / r), $MachinePrecision] + -0.5), $MachinePrecision] * r), $MachinePrecision], If[LessEqual[r, 4.25e+40], (-q$95$m), N[(N[((-q$95$m) * q$95$m), $MachinePrecision] * N[(N[(N[(p / r), $MachinePrecision] + 1.0), $MachinePrecision] / r), $MachinePrecision]), $MachinePrecision]]]
                          
                          \begin{array}{l}
                          q_m = \left|q\right|
                          \\
                          [p, r, q_m] = \mathsf{sort}([p, r, q_m])\\
                          \\
                          \begin{array}{l}
                          \mathbf{if}\;r \leq -2.15 \cdot 10^{-175}:\\
                          \;\;\;\;\mathsf{fma}\left(\left(\left|p\right| + p\right) + \left|r\right|, \frac{0.5}{r}, -0.5\right) \cdot r\\
                          
                          \mathbf{elif}\;r \leq 4.25 \cdot 10^{+40}:\\
                          \;\;\;\;-q\_m\\
                          
                          \mathbf{else}:\\
                          \;\;\;\;\left(\left(-q\_m\right) \cdot q\_m\right) \cdot \frac{\frac{p}{r} + 1}{r}\\
                          
                          
                          \end{array}
                          \end{array}
                          
                          Derivation
                          1. Split input into 3 regimes
                          2. if r < -2.14999999999999999e-175

                            1. Initial program 21.3%

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

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

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

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

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

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

                              if -2.14999999999999999e-175 < r < 4.24999999999999998e40

                              1. Initial program 31.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.f6424.5

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

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

                              if 4.24999999999999998e40 < r

                              1. Initial program 8.7%

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

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

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

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

                                  \[\leadsto \left(\left(-q\right) \cdot q\right) \cdot \color{blue}{\frac{\frac{p}{r} + 1}{r}} \]
                              7. Recombined 3 regimes into one program.
                              8. Add Preprocessing

                              Alternative 7: 41.1% accurate, 7.3× speedup?

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

                                1. Initial program 24.6%

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

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

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

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

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

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

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

                                  if 2.20000000000000009e-205 < q < 7.1999999999999997e-27

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

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

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

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

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

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

                                    if 7.1999999999999997e-27 < q

                                    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 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.f6452.9

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

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

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

                                    1. Initial program 23.7%

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

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

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

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

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

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

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

                                      if 9.00000000000000031e-67 < q

                                      1. Initial program 21.1%

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

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

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

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

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

                                    Alternative 9: 35.4% accurate, 83.3× speedup?

                                    \[\begin{array}{l} q_m = \left|q\right| \\ [p, r, q_m] = \mathsf{sort}([p, r, q_m])\\ \\ -q\_m \end{array} \]
                                    q_m = (fabs.f64 q)
                                    NOTE: p, r, and q_m should be sorted in increasing order before calling this function.
                                    (FPCore (p r q_m) :precision binary64 (- q_m))
                                    q_m = fabs(q);
                                    assert(p < r && r < q_m);
                                    double code(double p, double r, double q_m) {
                                    	return -q_m;
                                    }
                                    
                                    q_m = 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 22.8%

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

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

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

                                        \[\leadsto \color{blue}{-q} \]
                                    5. Applied rewrites20.1%

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

                                    Reproduce

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