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

Percentage Accurate: 24.7% → 68.4%
Time: 10.2s
Alternatives: 6
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 6 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Initial Program: 24.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: 68.4% accurate, 0.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 := \mathsf{hypot}\left(2 \cdot q\_m, p\right)\\ t_1 := {t\_0}^{0.5}\\ t_2 := \frac{p}{t\_1}\\ \mathbf{if}\;r \leq 1.15 \cdot 10^{-291}:\\ \;\;\;\;\mathsf{fma}\left(\frac{r}{t\_1}, t\_2, \left(\left|p\right| - \mathsf{hypot}\left(p, q\_m \cdot 2\right)\right) + \left|r\right|\right) \cdot 0.5\\ \mathbf{elif}\;r \leq 1.15 \cdot 10^{+38}:\\ \;\;\;\;\mathsf{fma}\left(\frac{r}{\mathsf{fma}\left(0.0625 \cdot {4}^{0.25}, \sqrt{{\left({q\_m}^{3}\right)}^{-1}} \cdot \left(p \cdot p\right), \sqrt{q\_m} \cdot {4}^{0.25}\right)}, t\_2, \left(\left|p\right| + \left|r\right|\right) - t\_0\right) \cdot 0.5\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(-\mathsf{fma}\left(p, \frac{\frac{p}{r \cdot r} + {r}^{-1}}{r \cdot r}, {\left(r \cdot r\right)}^{-1}\right), p, \frac{-1}{r}\right), q\_m \cdot q\_m, 0.5 \cdot \left(\left(p + \left(\left|r\right| - r\right)\right) + \left|p\right|\right)\right)\\ \end{array} \end{array} \]
q_m = (fabs.f64 q)
NOTE: p, r, and q_m should be sorted in increasing order before calling this function.
(FPCore (p r q_m)
 :precision binary64
 (let* ((t_0 (hypot (* 2.0 q_m) p)) (t_1 (pow t_0 0.5)) (t_2 (/ p t_1)))
   (if (<= r 1.15e-291)
     (*
      (fma (/ r t_1) t_2 (+ (- (fabs p) (hypot p (* q_m 2.0))) (fabs r)))
      0.5)
     (if (<= r 1.15e+38)
       (*
        (fma
         (/
          r
          (fma
           (* 0.0625 (pow 4.0 0.25))
           (* (sqrt (pow (pow q_m 3.0) -1.0)) (* p p))
           (* (sqrt q_m) (pow 4.0 0.25))))
         t_2
         (- (+ (fabs p) (fabs r)) t_0))
        0.5)
       (fma
        (fma
         (-
          (fma
           p
           (/ (+ (/ p (* r r)) (pow r -1.0)) (* r r))
           (pow (* r r) -1.0)))
         p
         (/ -1.0 r))
        (* q_m q_m)
        (* 0.5 (+ (+ p (- (fabs r) r)) (fabs p))))))))
q_m = fabs(q);
assert(p < r && r < q_m);
double code(double p, double r, double q_m) {
	double t_0 = hypot((2.0 * q_m), p);
	double t_1 = pow(t_0, 0.5);
	double t_2 = p / t_1;
	double tmp;
	if (r <= 1.15e-291) {
		tmp = fma((r / t_1), t_2, ((fabs(p) - hypot(p, (q_m * 2.0))) + fabs(r))) * 0.5;
	} else if (r <= 1.15e+38) {
		tmp = fma((r / fma((0.0625 * pow(4.0, 0.25)), (sqrt(pow(pow(q_m, 3.0), -1.0)) * (p * p)), (sqrt(q_m) * pow(4.0, 0.25)))), t_2, ((fabs(p) + fabs(r)) - t_0)) * 0.5;
	} else {
		tmp = fma(fma(-fma(p, (((p / (r * r)) + pow(r, -1.0)) / (r * r)), pow((r * r), -1.0)), p, (-1.0 / r)), (q_m * q_m), (0.5 * ((p + (fabs(r) - r)) + fabs(p))));
	}
	return tmp;
}
q_m = abs(q)
p, r, q_m = sort([p, r, q_m])
function code(p, r, q_m)
	t_0 = hypot(Float64(2.0 * q_m), p)
	t_1 = t_0 ^ 0.5
	t_2 = Float64(p / t_1)
	tmp = 0.0
	if (r <= 1.15e-291)
		tmp = Float64(fma(Float64(r / t_1), t_2, Float64(Float64(abs(p) - hypot(p, Float64(q_m * 2.0))) + abs(r))) * 0.5);
	elseif (r <= 1.15e+38)
		tmp = Float64(fma(Float64(r / fma(Float64(0.0625 * (4.0 ^ 0.25)), Float64(sqrt(((q_m ^ 3.0) ^ -1.0)) * Float64(p * p)), Float64(sqrt(q_m) * (4.0 ^ 0.25)))), t_2, Float64(Float64(abs(p) + abs(r)) - t_0)) * 0.5);
	else
		tmp = fma(fma(Float64(-fma(p, Float64(Float64(Float64(p / Float64(r * r)) + (r ^ -1.0)) / Float64(r * r)), (Float64(r * r) ^ -1.0))), p, Float64(-1.0 / r)), Float64(q_m * q_m), Float64(0.5 * Float64(Float64(p + Float64(abs(r) - r)) + abs(p))));
	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[Sqrt[N[(2.0 * q$95$m), $MachinePrecision] ^ 2 + p ^ 2], $MachinePrecision]}, Block[{t$95$1 = N[Power[t$95$0, 0.5], $MachinePrecision]}, Block[{t$95$2 = N[(p / t$95$1), $MachinePrecision]}, If[LessEqual[r, 1.15e-291], N[(N[(N[(r / t$95$1), $MachinePrecision] * t$95$2 + N[(N[(N[Abs[p], $MachinePrecision] - N[Sqrt[p ^ 2 + N[(q$95$m * 2.0), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision] + N[Abs[r], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision], If[LessEqual[r, 1.15e+38], N[(N[(N[(r / N[(N[(0.0625 * N[Power[4.0, 0.25], $MachinePrecision]), $MachinePrecision] * N[(N[Sqrt[N[Power[N[Power[q$95$m, 3.0], $MachinePrecision], -1.0], $MachinePrecision]], $MachinePrecision] * N[(p * p), $MachinePrecision]), $MachinePrecision] + N[(N[Sqrt[q$95$m], $MachinePrecision] * N[Power[4.0, 0.25], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * t$95$2 + N[(N[(N[Abs[p], $MachinePrecision] + N[Abs[r], $MachinePrecision]), $MachinePrecision] - t$95$0), $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision], N[(N[((-N[(p * N[(N[(N[(p / N[(r * r), $MachinePrecision]), $MachinePrecision] + N[Power[r, -1.0], $MachinePrecision]), $MachinePrecision] / N[(r * r), $MachinePrecision]), $MachinePrecision] + N[Power[N[(r * r), $MachinePrecision], -1.0], $MachinePrecision]), $MachinePrecision]) * p + N[(-1.0 / r), $MachinePrecision]), $MachinePrecision] * N[(q$95$m * q$95$m), $MachinePrecision] + N[(0.5 * N[(N[(p + N[(N[Abs[r], $MachinePrecision] - r), $MachinePrecision]), $MachinePrecision] + N[Abs[p], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}
q_m = \left|q\right|
\\
[p, r, q_m] = \mathsf{sort}([p, r, q_m])\\
\\
\begin{array}{l}
t_0 := \mathsf{hypot}\left(2 \cdot q\_m, p\right)\\
t_1 := {t\_0}^{0.5}\\
t_2 := \frac{p}{t\_1}\\
\mathbf{if}\;r \leq 1.15 \cdot 10^{-291}:\\
\;\;\;\;\mathsf{fma}\left(\frac{r}{t\_1}, t\_2, \left(\left|p\right| - \mathsf{hypot}\left(p, q\_m \cdot 2\right)\right) + \left|r\right|\right) \cdot 0.5\\

\mathbf{elif}\;r \leq 1.15 \cdot 10^{+38}:\\
\;\;\;\;\mathsf{fma}\left(\frac{r}{\mathsf{fma}\left(0.0625 \cdot {4}^{0.25}, \sqrt{{\left({q\_m}^{3}\right)}^{-1}} \cdot \left(p \cdot p\right), \sqrt{q\_m} \cdot {4}^{0.25}\right)}, t\_2, \left(\left|p\right| + \left|r\right|\right) - t\_0\right) \cdot 0.5\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(-\mathsf{fma}\left(p, \frac{\frac{p}{r \cdot r} + {r}^{-1}}{r \cdot r}, {\left(r \cdot r\right)}^{-1}\right), p, \frac{-1}{r}\right), q\_m \cdot q\_m, 0.5 \cdot \left(\left(p + \left(\left|r\right| - r\right)\right) + \left|p\right|\right)\right)\\


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

    1. Initial program 27.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 r around 0

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

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

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

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

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

        \[\leadsto \mathsf{fma}\left(\sqrt{\frac{1}{\mathsf{fma}\left(q \cdot q, 4, p \cdot p\right)}}, r \cdot p, \left(\left|p\right| - \sqrt{\mathsf{fma}\left(q \cdot q, 4, p \cdot p\right)}\right) + \left|r\right|\right) \cdot 0.5 \]
      2. Applied rewrites38.0%

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

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

        if 1.15e-291 < r < 1.1500000000000001e38

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

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

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

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

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

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

            \[\leadsto \mathsf{fma}\left(\sqrt{\frac{1}{\mathsf{fma}\left(q \cdot q, 4, p \cdot p\right)}}, r \cdot p, \left(\left|p\right| - \sqrt{\mathsf{fma}\left(q \cdot q, 4, p \cdot p\right)}\right) + \left|r\right|\right) \cdot 0.5 \]
          2. Applied rewrites52.7%

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

            \[\leadsto \mathsf{fma}\left(\frac{r}{\frac{1}{16} \cdot \left({4}^{\frac{1}{4}} \cdot \left({p}^{2} \cdot \sqrt{\frac{1}{{q}^{3}}}\right)\right) + {4}^{\frac{1}{4}} \cdot \sqrt{q}}, \frac{p}{{\left(\mathsf{hypot}\left(2 \cdot q, p\right)\right)}^{\frac{1}{2}}}, \left(\left|p\right| + \left|r\right|\right) - \mathsf{hypot}\left(2 \cdot q, p\right)\right) \cdot \frac{1}{2} \]
          4. Step-by-step derivation
            1. Applied rewrites36.8%

              \[\leadsto \mathsf{fma}\left(\frac{r}{\mathsf{fma}\left(0.0625 \cdot {4}^{0.25}, \sqrt{\frac{1}{{q}^{3}}} \cdot \left(p \cdot p\right), \sqrt{q} \cdot {4}^{0.25}\right)}, \frac{p}{{\left(\mathsf{hypot}\left(2 \cdot q, p\right)\right)}^{0.5}}, \left(\left|p\right| + \left|r\right|\right) - \mathsf{hypot}\left(2 \cdot q, p\right)\right) \cdot 0.5 \]

            if 1.1500000000000001e38 < r

            1. Initial program 4.9%

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

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

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

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

              \[\leadsto \mathsf{fma}\left(\mathsf{fma}\left(-\mathsf{fma}\left(p, \frac{\frac{p}{r \cdot r} + \frac{1}{r}}{r \cdot r}, \frac{1}{r \cdot r}\right), p, \frac{-1}{r}\right), \color{blue}{q \cdot q}, 0.5 \cdot \left(\left(p + \left(\left|r\right| - r\right)\right) + \left|p\right|\right)\right) \]
          5. Recombined 3 regimes into one program.
          6. Final simplification47.3%

            \[\leadsto \begin{array}{l} \mathbf{if}\;r \leq 1.15 \cdot 10^{-291}:\\ \;\;\;\;\mathsf{fma}\left(\frac{r}{{\left(\mathsf{hypot}\left(2 \cdot q, p\right)\right)}^{0.5}}, \frac{p}{{\left(\mathsf{hypot}\left(2 \cdot q, p\right)\right)}^{0.5}}, \left(\left|p\right| - \mathsf{hypot}\left(p, q \cdot 2\right)\right) + \left|r\right|\right) \cdot 0.5\\ \mathbf{elif}\;r \leq 1.15 \cdot 10^{+38}:\\ \;\;\;\;\mathsf{fma}\left(\frac{r}{\mathsf{fma}\left(0.0625 \cdot {4}^{0.25}, \sqrt{{\left({q}^{3}\right)}^{-1}} \cdot \left(p \cdot p\right), \sqrt{q} \cdot {4}^{0.25}\right)}, \frac{p}{{\left(\mathsf{hypot}\left(2 \cdot q, p\right)\right)}^{0.5}}, \left(\left|p\right| + \left|r\right|\right) - \mathsf{hypot}\left(2 \cdot q, p\right)\right) \cdot 0.5\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(-\mathsf{fma}\left(p, \frac{\frac{p}{r \cdot r} + {r}^{-1}}{r \cdot r}, {\left(r \cdot r\right)}^{-1}\right), p, \frac{-1}{r}\right), q \cdot q, 0.5 \cdot \left(\left(p + \left(\left|r\right| - r\right)\right) + \left|p\right|\right)\right)\\ \end{array} \]
          7. Add Preprocessing

          Alternative 2: 64.9% accurate, 0.4× 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(\mathsf{hypot}\left(2 \cdot q\_m, p\right)\right)}^{0.5}\\ \mathbf{if}\;r \leq 1.8 \cdot 10^{+38}:\\ \;\;\;\;\mathsf{fma}\left(\frac{r}{t\_0}, \frac{p}{t\_0}, \left(\left|p\right| - \mathsf{hypot}\left(p, q\_m \cdot 2\right)\right) + \left|r\right|\right) \cdot 0.5\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(-\mathsf{fma}\left(p, \frac{\frac{p}{r \cdot r} + {r}^{-1}}{r \cdot r}, {\left(r \cdot r\right)}^{-1}\right), p, \frac{-1}{r}\right), q\_m \cdot q\_m, 0.5 \cdot \left(\left(p + \left(\left|r\right| - r\right)\right) + \left|p\right|\right)\right)\\ \end{array} \end{array} \]
          q_m = (fabs.f64 q)
          NOTE: p, r, and q_m should be sorted in increasing order before calling this function.
          (FPCore (p r q_m)
           :precision binary64
           (let* ((t_0 (pow (hypot (* 2.0 q_m) p) 0.5)))
             (if (<= r 1.8e+38)
               (*
                (fma (/ r t_0) (/ p t_0) (+ (- (fabs p) (hypot p (* q_m 2.0))) (fabs r)))
                0.5)
               (fma
                (fma
                 (-
                  (fma p (/ (+ (/ p (* r r)) (pow r -1.0)) (* r r)) (pow (* r r) -1.0)))
                 p
                 (/ -1.0 r))
                (* q_m q_m)
                (* 0.5 (+ (+ p (- (fabs r) r)) (fabs p)))))))
          q_m = fabs(q);
          assert(p < r && r < q_m);
          double code(double p, double r, double q_m) {
          	double t_0 = pow(hypot((2.0 * q_m), p), 0.5);
          	double tmp;
          	if (r <= 1.8e+38) {
          		tmp = fma((r / t_0), (p / t_0), ((fabs(p) - hypot(p, (q_m * 2.0))) + fabs(r))) * 0.5;
          	} else {
          		tmp = fma(fma(-fma(p, (((p / (r * r)) + pow(r, -1.0)) / (r * r)), pow((r * r), -1.0)), p, (-1.0 / r)), (q_m * q_m), (0.5 * ((p + (fabs(r) - r)) + fabs(p))));
          	}
          	return tmp;
          }
          
          q_m = abs(q)
          p, r, q_m = sort([p, r, q_m])
          function code(p, r, q_m)
          	t_0 = hypot(Float64(2.0 * q_m), p) ^ 0.5
          	tmp = 0.0
          	if (r <= 1.8e+38)
          		tmp = Float64(fma(Float64(r / t_0), Float64(p / t_0), Float64(Float64(abs(p) - hypot(p, Float64(q_m * 2.0))) + abs(r))) * 0.5);
          	else
          		tmp = fma(fma(Float64(-fma(p, Float64(Float64(Float64(p / Float64(r * r)) + (r ^ -1.0)) / Float64(r * r)), (Float64(r * r) ^ -1.0))), p, Float64(-1.0 / r)), Float64(q_m * q_m), Float64(0.5 * Float64(Float64(p + Float64(abs(r) - r)) + abs(p))));
          	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[Power[N[Sqrt[N[(2.0 * q$95$m), $MachinePrecision] ^ 2 + p ^ 2], $MachinePrecision], 0.5], $MachinePrecision]}, If[LessEqual[r, 1.8e+38], N[(N[(N[(r / t$95$0), $MachinePrecision] * N[(p / t$95$0), $MachinePrecision] + N[(N[(N[Abs[p], $MachinePrecision] - N[Sqrt[p ^ 2 + N[(q$95$m * 2.0), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision] + N[Abs[r], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision], N[(N[((-N[(p * N[(N[(N[(p / N[(r * r), $MachinePrecision]), $MachinePrecision] + N[Power[r, -1.0], $MachinePrecision]), $MachinePrecision] / N[(r * r), $MachinePrecision]), $MachinePrecision] + N[Power[N[(r * r), $MachinePrecision], -1.0], $MachinePrecision]), $MachinePrecision]) * p + N[(-1.0 / r), $MachinePrecision]), $MachinePrecision] * N[(q$95$m * q$95$m), $MachinePrecision] + N[(0.5 * N[(N[(p + N[(N[Abs[r], $MachinePrecision] - r), $MachinePrecision]), $MachinePrecision] + N[Abs[p], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $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(\mathsf{hypot}\left(2 \cdot q\_m, p\right)\right)}^{0.5}\\
          \mathbf{if}\;r \leq 1.8 \cdot 10^{+38}:\\
          \;\;\;\;\mathsf{fma}\left(\frac{r}{t\_0}, \frac{p}{t\_0}, \left(\left|p\right| - \mathsf{hypot}\left(p, q\_m \cdot 2\right)\right) + \left|r\right|\right) \cdot 0.5\\
          
          \mathbf{else}:\\
          \;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(-\mathsf{fma}\left(p, \frac{\frac{p}{r \cdot r} + {r}^{-1}}{r \cdot r}, {\left(r \cdot r\right)}^{-1}\right), p, \frac{-1}{r}\right), q\_m \cdot q\_m, 0.5 \cdot \left(\left(p + \left(\left|r\right| - r\right)\right) + \left|p\right|\right)\right)\\
          
          
          \end{array}
          \end{array}
          
          Derivation
          1. Split input into 2 regimes
          2. if r < 1.79999999999999985e38

            1. Initial program 31.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 r around 0

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

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

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

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

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

                \[\leadsto \mathsf{fma}\left(\sqrt{\frac{1}{\mathsf{fma}\left(q \cdot q, 4, p \cdot p\right)}}, r \cdot p, \left(\left|p\right| - \sqrt{\mathsf{fma}\left(q \cdot q, 4, p \cdot p\right)}\right) + \left|r\right|\right) \cdot 0.5 \]
              2. Applied rewrites42.7%

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

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

                if 1.79999999999999985e38 < r

                1. Initial program 4.9%

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

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

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

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

                  \[\leadsto \mathsf{fma}\left(\mathsf{fma}\left(-\mathsf{fma}\left(p, \frac{\frac{p}{r \cdot r} + \frac{1}{r}}{r \cdot r}, \frac{1}{r \cdot r}\right), p, \frac{-1}{r}\right), \color{blue}{q \cdot q}, 0.5 \cdot \left(\left(p + \left(\left|r\right| - r\right)\right) + \left|p\right|\right)\right) \]
              4. Recombined 2 regimes into one program.
              5. Final simplification52.2%

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

              Alternative 3: 59.3% accurate, 0.6× speedup?

              \[\begin{array}{l} q_m = \left|q\right| \\ [p, r, q_m] = \mathsf{sort}([p, r, q_m])\\ \\ \begin{array}{l} t_0 := \mathsf{hypot}\left(p, q\_m \cdot 2\right)\\ t_1 := \sqrt{t\_0}\\ \mathbf{if}\;r \leq -2.35 \cdot 10^{-6}:\\ \;\;\;\;\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 1.15 \cdot 10^{+38}:\\ \;\;\;\;\mathsf{fma}\left(\frac{r}{t\_1}, \frac{p}{t\_1}, \left(\left|r\right| + \left|p\right|\right) - t\_0\right) \cdot 0.5\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(-\mathsf{fma}\left(p, \frac{\frac{p}{r \cdot r} + {r}^{-1}}{r \cdot r}, {\left(r \cdot r\right)}^{-1}\right), p, \frac{-1}{r}\right), q\_m \cdot q\_m, 0.5 \cdot \left(\left(p + \left(\left|r\right| - r\right)\right) + \left|p\right|\right)\right)\\ \end{array} \end{array} \]
              q_m = (fabs.f64 q)
              NOTE: p, r, and q_m should be sorted in increasing order before calling this function.
              (FPCore (p r q_m)
               :precision binary64
               (let* ((t_0 (hypot p (* q_m 2.0))) (t_1 (sqrt t_0)))
                 (if (<= r -2.35e-6)
                   (* (fma (+ (+ (fabs p) p) (fabs r)) (/ 0.5 r) -0.5) r)
                   (if (<= r 1.15e+38)
                     (* (fma (/ r t_1) (/ p t_1) (- (+ (fabs r) (fabs p)) t_0)) 0.5)
                     (fma
                      (fma
                       (-
                        (fma
                         p
                         (/ (+ (/ p (* r r)) (pow r -1.0)) (* r r))
                         (pow (* r r) -1.0)))
                       p
                       (/ -1.0 r))
                      (* q_m q_m)
                      (* 0.5 (+ (+ p (- (fabs r) r)) (fabs p))))))))
              q_m = fabs(q);
              assert(p < r && r < q_m);
              double code(double p, double r, double q_m) {
              	double t_0 = hypot(p, (q_m * 2.0));
              	double t_1 = sqrt(t_0);
              	double tmp;
              	if (r <= -2.35e-6) {
              		tmp = fma(((fabs(p) + p) + fabs(r)), (0.5 / r), -0.5) * r;
              	} else if (r <= 1.15e+38) {
              		tmp = fma((r / t_1), (p / t_1), ((fabs(r) + fabs(p)) - t_0)) * 0.5;
              	} else {
              		tmp = fma(fma(-fma(p, (((p / (r * r)) + pow(r, -1.0)) / (r * r)), pow((r * r), -1.0)), p, (-1.0 / r)), (q_m * q_m), (0.5 * ((p + (fabs(r) - r)) + fabs(p))));
              	}
              	return tmp;
              }
              
              q_m = abs(q)
              p, r, q_m = sort([p, r, q_m])
              function code(p, r, q_m)
              	t_0 = hypot(p, Float64(q_m * 2.0))
              	t_1 = sqrt(t_0)
              	tmp = 0.0
              	if (r <= -2.35e-6)
              		tmp = Float64(fma(Float64(Float64(abs(p) + p) + abs(r)), Float64(0.5 / r), -0.5) * r);
              	elseif (r <= 1.15e+38)
              		tmp = Float64(fma(Float64(r / t_1), Float64(p / t_1), Float64(Float64(abs(r) + abs(p)) - t_0)) * 0.5);
              	else
              		tmp = fma(fma(Float64(-fma(p, Float64(Float64(Float64(p / Float64(r * r)) + (r ^ -1.0)) / Float64(r * r)), (Float64(r * r) ^ -1.0))), p, Float64(-1.0 / r)), Float64(q_m * q_m), Float64(0.5 * Float64(Float64(p + Float64(abs(r) - r)) + abs(p))));
              	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[Sqrt[p ^ 2 + N[(q$95$m * 2.0), $MachinePrecision] ^ 2], $MachinePrecision]}, Block[{t$95$1 = N[Sqrt[t$95$0], $MachinePrecision]}, If[LessEqual[r, -2.35e-6], 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, 1.15e+38], N[(N[(N[(r / t$95$1), $MachinePrecision] * N[(p / t$95$1), $MachinePrecision] + N[(N[(N[Abs[r], $MachinePrecision] + N[Abs[p], $MachinePrecision]), $MachinePrecision] - t$95$0), $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision], N[(N[((-N[(p * N[(N[(N[(p / N[(r * r), $MachinePrecision]), $MachinePrecision] + N[Power[r, -1.0], $MachinePrecision]), $MachinePrecision] / N[(r * r), $MachinePrecision]), $MachinePrecision] + N[Power[N[(r * r), $MachinePrecision], -1.0], $MachinePrecision]), $MachinePrecision]) * p + N[(-1.0 / r), $MachinePrecision]), $MachinePrecision] * N[(q$95$m * q$95$m), $MachinePrecision] + N[(0.5 * N[(N[(p + N[(N[Abs[r], $MachinePrecision] - r), $MachinePrecision]), $MachinePrecision] + N[Abs[p], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]
              
              \begin{array}{l}
              q_m = \left|q\right|
              \\
              [p, r, q_m] = \mathsf{sort}([p, r, q_m])\\
              \\
              \begin{array}{l}
              t_0 := \mathsf{hypot}\left(p, q\_m \cdot 2\right)\\
              t_1 := \sqrt{t\_0}\\
              \mathbf{if}\;r \leq -2.35 \cdot 10^{-6}:\\
              \;\;\;\;\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 1.15 \cdot 10^{+38}:\\
              \;\;\;\;\mathsf{fma}\left(\frac{r}{t\_1}, \frac{p}{t\_1}, \left(\left|r\right| + \left|p\right|\right) - t\_0\right) \cdot 0.5\\
              
              \mathbf{else}:\\
              \;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(-\mathsf{fma}\left(p, \frac{\frac{p}{r \cdot r} + {r}^{-1}}{r \cdot r}, {\left(r \cdot r\right)}^{-1}\right), p, \frac{-1}{r}\right), q\_m \cdot q\_m, 0.5 \cdot \left(\left(p + \left(\left|r\right| - r\right)\right) + \left|p\right|\right)\right)\\
              
              
              \end{array}
              \end{array}
              
              Derivation
              1. Split input into 3 regimes
              2. if r < -2.34999999999999995e-6

                1. Initial program 17.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 rewrites3.3%

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

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

                  if -2.34999999999999995e-6 < r < 1.1500000000000001e38

                  1. Initial program 39.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 r around 0

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

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

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

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

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

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

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

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

                      if 1.1500000000000001e38 < r

                      1. Initial program 4.9%

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

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

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

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

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

                      \[\leadsto \begin{array}{l} \mathbf{if}\;r \leq -2.35 \cdot 10^{-6}:\\ \;\;\;\;\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 1.15 \cdot 10^{+38}:\\ \;\;\;\;\mathsf{fma}\left(\frac{r}{\sqrt{\mathsf{hypot}\left(p, q \cdot 2\right)}}, \frac{p}{\sqrt{\mathsf{hypot}\left(p, q \cdot 2\right)}}, \left(\left|r\right| + \left|p\right|\right) - \mathsf{hypot}\left(p, q \cdot 2\right)\right) \cdot 0.5\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(-\mathsf{fma}\left(p, \frac{\frac{p}{r \cdot r} + {r}^{-1}}{r \cdot r}, {\left(r \cdot r\right)}^{-1}\right), p, \frac{-1}{r}\right), q \cdot q, 0.5 \cdot \left(\left(p + \left(\left|r\right| - r\right)\right) + \left|p\right|\right)\right)\\ \end{array} \]
                    6. Add Preprocessing

                    Alternative 4: 55.1% accurate, 2.0× speedup?

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

                      1. Initial program 21.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 p around 0

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

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

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

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

                        if 1.9999999999999998e-198 < (pow.f64 q #s(literal 2 binary64))

                        1. Initial program 27.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.f6429.5

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

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

                      Alternative 5: 40.8% accurate, 2.0× speedup?

                      \[\begin{array}{l} q_m = \left|q\right| \\ [p, r, q_m] = \mathsf{sort}([p, r, q_m])\\ \\ \begin{array}{l} \mathbf{if}\;{q\_m}^{2} \leq 2 \cdot 10^{-198}:\\ \;\;\;\;\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 (<= (pow q_m 2.0) 2e-198) (* (+ (+ 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 (pow(q_m, 2.0) <= 2e-198) {
                      		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 ** 2.0d0) <= 2d-198) 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 (Math.pow(q_m, 2.0) <= 2e-198) {
                      		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 math.pow(q_m, 2.0) <= 2e-198:
                      		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 ^ 2.0) <= 2e-198)
                      		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 ^ 2.0) <= 2e-198)
                      		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[N[Power[q$95$m, 2.0], $MachinePrecision], 2e-198], 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}^{2} \leq 2 \cdot 10^{-198}:\\
                      \;\;\;\;\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 (pow.f64 q #s(literal 2 binary64)) < 1.9999999999999998e-198

                        1. Initial program 21.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 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 rewrites13.0%

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

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

                          if 1.9999999999999998e-198 < (pow.f64 q #s(literal 2 binary64))

                          1. Initial program 27.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.f6429.5

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

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

                        Alternative 6: 35.6% 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 25.1%

                          \[\frac{1}{2} \cdot \left(\left(\left|p\right| + \left|r\right|\right) - \sqrt{{\left(p - r\right)}^{2} + 4 \cdot {q}^{2}}\right) \]
                        2. 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.f6421.1

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

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

                        Reproduce

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