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

Percentage Accurate: 24.1% → 62.6%
Time: 7.3s
Alternatives: 6
Speedup: 19.7×

Specification

?
\[\frac{1}{2} \cdot \left(\left(\left|p\right| + \left|r\right|\right) - \sqrt{{\left(p - r\right)}^{2} + 4 \cdot {q}^{2}}\right) \]
(FPCore (p r q)
  :precision binary64
  :pre TRUE
  (*
 (/ 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)
use fmin_fmax_functions
    real(8), intent (in) :: p
    real(8), intent (in) :: r
    real(8), intent (in) :: q
    code = (1.0d0 / 2.0d0) * ((abs(p) + abs(r)) - sqrt((((p - r) ** 2.0d0) + (4.0d0 * (q ** 2.0d0)))))
end function
public static double code(double p, double r, double q) {
	return (1.0 / 2.0) * ((Math.abs(p) + Math.abs(r)) - Math.sqrt((Math.pow((p - r), 2.0) + (4.0 * Math.pow(q, 2.0)))));
}
def code(p, r, q):
	return (1.0 / 2.0) * ((math.fabs(p) + math.fabs(r)) - math.sqrt((math.pow((p - r), 2.0) + (4.0 * math.pow(q, 2.0)))))
function code(p, r, q)
	return Float64(Float64(1.0 / 2.0) * Float64(Float64(abs(p) + abs(r)) - sqrt(Float64((Float64(p - r) ^ 2.0) + Float64(4.0 * (q ^ 2.0))))))
end
function tmp = code(p, r, q)
	tmp = (1.0 / 2.0) * ((abs(p) + abs(r)) - sqrt((((p - r) ^ 2.0) + (4.0 * (q ^ 2.0)))));
end
code[p_, r_, q_] := N[(N[(1.0 / 2.0), $MachinePrecision] * N[(N[(N[Abs[p], $MachinePrecision] + N[Abs[r], $MachinePrecision]), $MachinePrecision] - N[Sqrt[N[(N[Power[N[(p - r), $MachinePrecision], 2.0], $MachinePrecision] + N[(4.0 * N[Power[q, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
f(p, r, q):
	p in [-inf, +inf],
	r in [-inf, +inf],
	q in [-inf, +inf]
code: THEORY
BEGIN
f(p, r, q: real): real =
	((1) / (2)) * (((abs(p)) + (abs(r))) - (sqrt((((p - r) ^ (2)) + ((4) * (q ^ (2)))))))
END code
\frac{1}{2} \cdot \left(\left(\left|p\right| + \left|r\right|\right) - \sqrt{{\left(p - r\right)}^{2} + 4 \cdot {q}^{2}}\right)

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.1% accurate, 1.0× speedup?

\[\frac{1}{2} \cdot \left(\left(\left|p\right| + \left|r\right|\right) - \sqrt{{\left(p - r\right)}^{2} + 4 \cdot {q}^{2}}\right) \]
(FPCore (p r q)
  :precision binary64
  :pre TRUE
  (*
 (/ 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)
use fmin_fmax_functions
    real(8), intent (in) :: p
    real(8), intent (in) :: r
    real(8), intent (in) :: q
    code = (1.0d0 / 2.0d0) * ((abs(p) + abs(r)) - sqrt((((p - r) ** 2.0d0) + (4.0d0 * (q ** 2.0d0)))))
end function
public static double code(double p, double r, double q) {
	return (1.0 / 2.0) * ((Math.abs(p) + Math.abs(r)) - Math.sqrt((Math.pow((p - r), 2.0) + (4.0 * Math.pow(q, 2.0)))));
}
def code(p, r, q):
	return (1.0 / 2.0) * ((math.fabs(p) + math.fabs(r)) - math.sqrt((math.pow((p - r), 2.0) + (4.0 * math.pow(q, 2.0)))))
function code(p, r, q)
	return Float64(Float64(1.0 / 2.0) * Float64(Float64(abs(p) + abs(r)) - sqrt(Float64((Float64(p - r) ^ 2.0) + Float64(4.0 * (q ^ 2.0))))))
end
function tmp = code(p, r, q)
	tmp = (1.0 / 2.0) * ((abs(p) + abs(r)) - sqrt((((p - r) ^ 2.0) + (4.0 * (q ^ 2.0)))));
end
code[p_, r_, q_] := N[(N[(1.0 / 2.0), $MachinePrecision] * N[(N[(N[Abs[p], $MachinePrecision] + N[Abs[r], $MachinePrecision]), $MachinePrecision] - N[Sqrt[N[(N[Power[N[(p - r), $MachinePrecision], 2.0], $MachinePrecision] + N[(4.0 * N[Power[q, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
f(p, r, q):
	p in [-inf, +inf],
	r in [-inf, +inf],
	q in [-inf, +inf]
code: THEORY
BEGIN
f(p, r, q: real): real =
	((1) / (2)) * (((abs(p)) + (abs(r))) - (sqrt((((p - r) ^ (2)) + ((4) * (q ^ (2)))))))
END code
\frac{1}{2} \cdot \left(\left(\left|p\right| + \left|r\right|\right) - \sqrt{{\left(p - r\right)}^{2} + 4 \cdot {q}^{2}}\right)

Alternative 1: 62.6% accurate, 0.6× speedup?

\[\begin{array}{l} t_0 := \left|\mathsf{max}\left(p, r\right)\right|\\ t_1 := \mathsf{min}\left(p, r\right) - \mathsf{max}\left(p, r\right)\\ t_2 := \left|t\_1\right|\\ t_3 := \left|\mathsf{min}\left(p, r\right)\right|\\ t_4 := \sqrt{t\_3}\\ \mathbf{if}\;{q}^{2} \leq 5 \cdot 10^{-224}:\\ \;\;\;\;\mathsf{fma}\left(0.5, t\_3, 0.5 \cdot \mathsf{min}\left(p, r\right)\right)\\ \mathbf{elif}\;{q}^{2} \leq 2 \cdot 10^{+179}:\\ \;\;\;\;\left(\left(t\_0 + t\_3\right) - t\_2\right) \cdot 0.5 - \frac{q \cdot q}{t\_2}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(t\_4, t\_4 \cdot 0.5, \left(t\_0 - \mathsf{hypot}\left(q + q, t\_1\right)\right) \cdot 0.5\right)\\ \end{array} \]
(FPCore (p r q)
  :precision binary64
  :pre TRUE
  (let* ((t_0 (fabs (fmax p r)))
       (t_1 (- (fmin p r) (fmax p r)))
       (t_2 (fabs t_1))
       (t_3 (fabs (fmin p r)))
       (t_4 (sqrt t_3)))
  (if (<= (pow q 2.0) 5e-224)
    (fma 0.5 t_3 (* 0.5 (fmin p r)))
    (if (<= (pow q 2.0) 2e+179)
      (- (* (- (+ t_0 t_3) t_2) 0.5) (/ (* q q) t_2))
      (fma t_4 (* t_4 0.5) (* (- t_0 (hypot (+ q q) t_1)) 0.5))))))
double code(double p, double r, double q) {
	double t_0 = fabs(fmax(p, r));
	double t_1 = fmin(p, r) - fmax(p, r);
	double t_2 = fabs(t_1);
	double t_3 = fabs(fmin(p, r));
	double t_4 = sqrt(t_3);
	double tmp;
	if (pow(q, 2.0) <= 5e-224) {
		tmp = fma(0.5, t_3, (0.5 * fmin(p, r)));
	} else if (pow(q, 2.0) <= 2e+179) {
		tmp = (((t_0 + t_3) - t_2) * 0.5) - ((q * q) / t_2);
	} else {
		tmp = fma(t_4, (t_4 * 0.5), ((t_0 - hypot((q + q), t_1)) * 0.5));
	}
	return tmp;
}
function code(p, r, q)
	t_0 = abs(fmax(p, r))
	t_1 = Float64(fmin(p, r) - fmax(p, r))
	t_2 = abs(t_1)
	t_3 = abs(fmin(p, r))
	t_4 = sqrt(t_3)
	tmp = 0.0
	if ((q ^ 2.0) <= 5e-224)
		tmp = fma(0.5, t_3, Float64(0.5 * fmin(p, r)));
	elseif ((q ^ 2.0) <= 2e+179)
		tmp = Float64(Float64(Float64(Float64(t_0 + t_3) - t_2) * 0.5) - Float64(Float64(q * q) / t_2));
	else
		tmp = fma(t_4, Float64(t_4 * 0.5), Float64(Float64(t_0 - hypot(Float64(q + q), t_1)) * 0.5));
	end
	return tmp
end
code[p_, r_, q_] := Block[{t$95$0 = N[Abs[N[Max[p, r], $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(N[Min[p, r], $MachinePrecision] - N[Max[p, r], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[Abs[t$95$1], $MachinePrecision]}, Block[{t$95$3 = N[Abs[N[Min[p, r], $MachinePrecision]], $MachinePrecision]}, Block[{t$95$4 = N[Sqrt[t$95$3], $MachinePrecision]}, If[LessEqual[N[Power[q, 2.0], $MachinePrecision], 5e-224], N[(0.5 * t$95$3 + N[(0.5 * N[Min[p, r], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[Power[q, 2.0], $MachinePrecision], 2e+179], N[(N[(N[(N[(t$95$0 + t$95$3), $MachinePrecision] - t$95$2), $MachinePrecision] * 0.5), $MachinePrecision] - N[(N[(q * q), $MachinePrecision] / t$95$2), $MachinePrecision]), $MachinePrecision], N[(t$95$4 * N[(t$95$4 * 0.5), $MachinePrecision] + N[(N[(t$95$0 - N[Sqrt[N[(q + q), $MachinePrecision] ^ 2 + t$95$1 ^ 2], $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision]), $MachinePrecision]]]]]]]]
f(p, r, q):
	p in [-inf, +inf],
	r in [-inf, +inf],
	q in [-inf, +inf]
code: THEORY
BEGIN
f(p, r, q: real): real =
	LET tmp = IF (p > r) THEN p ELSE r ENDIF IN
	LET t_0 = (abs(tmp)) IN
		LET tmp_1 = IF (p < r) THEN p ELSE r ENDIF IN
		LET tmp_2 = IF (p > r) THEN p ELSE r ENDIF IN
		LET t_1 = (tmp_1 - tmp_2) IN
			LET t_2 = (abs(t_1)) IN
				LET tmp_3 = IF (p < r) THEN p ELSE r ENDIF IN
				LET t_3 = (abs(tmp_3)) IN
					LET t_4 = (sqrt(t_3)) IN
						LET tmp_6 = IF (p < r) THEN p ELSE r ENDIF IN
						LET tmp_7 = IF ((q ^ (2)) <= (199999999999999996091099546963028318915752778493452543828291966300228010772656544918538878468995967298844297195887900676839994006336880488768194581630088140609089562433891216654336)) THEN ((((t_0 + t_3) - t_2) * (5e-1)) - ((q * q) / t_2)) ELSE ((t_4 * (t_4 * (5e-1))) + ((t_0 - (sqrt((((q + q) ^ (2)) + (t_1 ^ (2)))))) * (5e-1))) ENDIF IN
						LET tmp_5 = IF ((q ^ (2)) <= (499999999999999985446953231405953187004000285153417599746840100991383165184323288723455329279773138643813346355731201716053364298848098380338701547237187340691844592992080114739689001542607083409411549265022024348697226710906840397444772420529571073058679206551489729134224153677729186130531955859985623877264199414009442916238742495490569493828709020342904011536226600493239142123792667615143265058502757292731879517381636236209020863797528431061698548026394597237405148362723326280011239694358499309954064432056402123608109520393194546983295367681421339511871337890625e-793)) THEN (((5e-1) * t_3) + ((5e-1) * tmp_6)) ELSE tmp_7 ENDIF IN
	tmp_5
END code
\begin{array}{l}
t_0 := \left|\mathsf{max}\left(p, r\right)\right|\\
t_1 := \mathsf{min}\left(p, r\right) - \mathsf{max}\left(p, r\right)\\
t_2 := \left|t\_1\right|\\
t_3 := \left|\mathsf{min}\left(p, r\right)\right|\\
t_4 := \sqrt{t\_3}\\
\mathbf{if}\;{q}^{2} \leq 5 \cdot 10^{-224}:\\
\;\;\;\;\mathsf{fma}\left(0.5, t\_3, 0.5 \cdot \mathsf{min}\left(p, r\right)\right)\\

\mathbf{elif}\;{q}^{2} \leq 2 \cdot 10^{+179}:\\
\;\;\;\;\left(\left(t\_0 + t\_3\right) - t\_2\right) \cdot 0.5 - \frac{q \cdot q}{t\_2}\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(t\_4, t\_4 \cdot 0.5, \left(t\_0 - \mathsf{hypot}\left(q + q, t\_1\right)\right) \cdot 0.5\right)\\


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

    1. Initial program 24.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. Applied rewrites21.7%

      \[\leadsto \mathsf{fma}\left(0.5, \left|p\right|, \left(\left|r\right| - \sqrt{\mathsf{fma}\left(q \cdot q, 4, \left(p - r\right) \cdot \left(p - r\right)\right)}\right) \cdot 0.5\right) \]
    3. Taylor expanded in p around -inf

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

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

      if 4.9999999999999999e-224 < (pow.f64 q #s(literal 2 binary64)) < 2e179

      1. Initial program 24.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. Taylor expanded in q around 0

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

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

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

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

        1. Initial program 24.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. Applied rewrites18.5%

          \[\leadsto \mathsf{fma}\left(\sqrt{\left|p\right|}, \sqrt{\left|p\right|} \cdot 0.5, \left(\left|r\right| - \sqrt{\mathsf{fma}\left(q \cdot q, 4, \left(p - r\right) \cdot \left(p - r\right)\right)}\right) \cdot 0.5\right) \]
        3. Step-by-step derivation
          1. Applied rewrites38.4%

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

        Alternative 2: 62.5% accurate, 0.7× speedup?

        \[\begin{array}{l} t_0 := \mathsf{min}\left(p, r\right) - \mathsf{max}\left(p, r\right)\\ t_1 := \left|t\_0\right|\\ t_2 := \left|\mathsf{min}\left(p, r\right)\right|\\ t_3 := \left|\mathsf{max}\left(p, r\right)\right| + t\_2\\ \mathbf{if}\;{q}^{2} \leq 5 \cdot 10^{-224}:\\ \;\;\;\;\mathsf{fma}\left(0.5, t\_2, 0.5 \cdot \mathsf{min}\left(p, r\right)\right)\\ \mathbf{elif}\;{q}^{2} \leq 2 \cdot 10^{+179}:\\ \;\;\;\;\left(t\_3 - t\_1\right) \cdot 0.5 - \frac{q \cdot q}{t\_1}\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \left(t\_3 - \mathsf{hypot}\left(q + q, t\_0\right)\right)\\ \end{array} \]
        (FPCore (p r q)
          :precision binary64
          :pre TRUE
          (let* ((t_0 (- (fmin p r) (fmax p r)))
               (t_1 (fabs t_0))
               (t_2 (fabs (fmin p r)))
               (t_3 (+ (fabs (fmax p r)) t_2)))
          (if (<= (pow q 2.0) 5e-224)
            (fma 0.5 t_2 (* 0.5 (fmin p r)))
            (if (<= (pow q 2.0) 2e+179)
              (- (* (- t_3 t_1) 0.5) (/ (* q q) t_1))
              (* 0.5 (- t_3 (hypot (+ q q) t_0)))))))
        double code(double p, double r, double q) {
        	double t_0 = fmin(p, r) - fmax(p, r);
        	double t_1 = fabs(t_0);
        	double t_2 = fabs(fmin(p, r));
        	double t_3 = fabs(fmax(p, r)) + t_2;
        	double tmp;
        	if (pow(q, 2.0) <= 5e-224) {
        		tmp = fma(0.5, t_2, (0.5 * fmin(p, r)));
        	} else if (pow(q, 2.0) <= 2e+179) {
        		tmp = ((t_3 - t_1) * 0.5) - ((q * q) / t_1);
        	} else {
        		tmp = 0.5 * (t_3 - hypot((q + q), t_0));
        	}
        	return tmp;
        }
        
        function code(p, r, q)
        	t_0 = Float64(fmin(p, r) - fmax(p, r))
        	t_1 = abs(t_0)
        	t_2 = abs(fmin(p, r))
        	t_3 = Float64(abs(fmax(p, r)) + t_2)
        	tmp = 0.0
        	if ((q ^ 2.0) <= 5e-224)
        		tmp = fma(0.5, t_2, Float64(0.5 * fmin(p, r)));
        	elseif ((q ^ 2.0) <= 2e+179)
        		tmp = Float64(Float64(Float64(t_3 - t_1) * 0.5) - Float64(Float64(q * q) / t_1));
        	else
        		tmp = Float64(0.5 * Float64(t_3 - hypot(Float64(q + q), t_0)));
        	end
        	return tmp
        end
        
        code[p_, r_, q_] := Block[{t$95$0 = N[(N[Min[p, r], $MachinePrecision] - N[Max[p, r], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[Abs[t$95$0], $MachinePrecision]}, Block[{t$95$2 = N[Abs[N[Min[p, r], $MachinePrecision]], $MachinePrecision]}, Block[{t$95$3 = N[(N[Abs[N[Max[p, r], $MachinePrecision]], $MachinePrecision] + t$95$2), $MachinePrecision]}, If[LessEqual[N[Power[q, 2.0], $MachinePrecision], 5e-224], N[(0.5 * t$95$2 + N[(0.5 * N[Min[p, r], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[Power[q, 2.0], $MachinePrecision], 2e+179], N[(N[(N[(t$95$3 - t$95$1), $MachinePrecision] * 0.5), $MachinePrecision] - N[(N[(q * q), $MachinePrecision] / t$95$1), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(t$95$3 - N[Sqrt[N[(q + q), $MachinePrecision] ^ 2 + t$95$0 ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]]
        
        f(p, r, q):
        	p in [-inf, +inf],
        	r in [-inf, +inf],
        	q in [-inf, +inf]
        code: THEORY
        BEGIN
        f(p, r, q: real): real =
        	LET tmp = IF (p < r) THEN p ELSE r ENDIF IN
        	LET tmp_1 = IF (p > r) THEN p ELSE r ENDIF IN
        	LET t_0 = (tmp - tmp_1) IN
        		LET t_1 = (abs(t_0)) IN
        			LET tmp_2 = IF (p < r) THEN p ELSE r ENDIF IN
        			LET t_2 = (abs(tmp_2)) IN
        				LET tmp_3 = IF (p > r) THEN p ELSE r ENDIF IN
        				LET t_3 = ((abs(tmp_3)) + t_2) IN
        					LET tmp_6 = IF (p < r) THEN p ELSE r ENDIF IN
        					LET tmp_7 = IF ((q ^ (2)) <= (199999999999999996091099546963028318915752778493452543828291966300228010772656544918538878468995967298844297195887900676839994006336880488768194581630088140609089562433891216654336)) THEN (((t_3 - t_1) * (5e-1)) - ((q * q) / t_1)) ELSE ((5e-1) * (t_3 - (sqrt((((q + q) ^ (2)) + (t_0 ^ (2))))))) ENDIF IN
        					LET tmp_5 = IF ((q ^ (2)) <= (499999999999999985446953231405953187004000285153417599746840100991383165184323288723455329279773138643813346355731201716053364298848098380338701547237187340691844592992080114739689001542607083409411549265022024348697226710906840397444772420529571073058679206551489729134224153677729186130531955859985623877264199414009442916238742495490569493828709020342904011536226600493239142123792667615143265058502757292731879517381636236209020863797528431061698548026394597237405148362723326280011239694358499309954064432056402123608109520393194546983295367681421339511871337890625e-793)) THEN (((5e-1) * t_2) + ((5e-1) * tmp_6)) ELSE tmp_7 ENDIF IN
        	tmp_5
        END code
        \begin{array}{l}
        t_0 := \mathsf{min}\left(p, r\right) - \mathsf{max}\left(p, r\right)\\
        t_1 := \left|t\_0\right|\\
        t_2 := \left|\mathsf{min}\left(p, r\right)\right|\\
        t_3 := \left|\mathsf{max}\left(p, r\right)\right| + t\_2\\
        \mathbf{if}\;{q}^{2} \leq 5 \cdot 10^{-224}:\\
        \;\;\;\;\mathsf{fma}\left(0.5, t\_2, 0.5 \cdot \mathsf{min}\left(p, r\right)\right)\\
        
        \mathbf{elif}\;{q}^{2} \leq 2 \cdot 10^{+179}:\\
        \;\;\;\;\left(t\_3 - t\_1\right) \cdot 0.5 - \frac{q \cdot q}{t\_1}\\
        
        \mathbf{else}:\\
        \;\;\;\;0.5 \cdot \left(t\_3 - \mathsf{hypot}\left(q + q, t\_0\right)\right)\\
        
        
        \end{array}
        
        Derivation
        1. Split input into 3 regimes
        2. if (pow.f64 q #s(literal 2 binary64)) < 4.9999999999999999e-224

          1. Initial program 24.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. Applied rewrites21.7%

            \[\leadsto \mathsf{fma}\left(0.5, \left|p\right|, \left(\left|r\right| - \sqrt{\mathsf{fma}\left(q \cdot q, 4, \left(p - r\right) \cdot \left(p - r\right)\right)}\right) \cdot 0.5\right) \]
          3. Taylor expanded in p around -inf

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

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

            if 4.9999999999999999e-224 < (pow.f64 q #s(literal 2 binary64)) < 2e179

            1. Initial program 24.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. Taylor expanded in q around 0

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

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

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

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

              1. Initial program 24.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. Applied rewrites24.1%

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

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

              Alternative 3: 61.6% accurate, 0.6× speedup?

              \[\begin{array}{l} t_0 := {\left(\left|q\right|\right)}^{2}\\ t_1 := \left|\mathsf{min}\left(p, r\right) - \mathsf{max}\left(p, r\right)\right|\\ t_2 := \left|\mathsf{min}\left(p, r\right)\right|\\ t_3 := \left|\mathsf{max}\left(p, r\right)\right| + t\_2\\ \mathbf{if}\;t\_0 \leq 5 \cdot 10^{-224}:\\ \;\;\;\;\mathsf{fma}\left(0.5, t\_2, 0.5 \cdot \mathsf{min}\left(p, r\right)\right)\\ \mathbf{elif}\;t\_0 \leq 2 \cdot 10^{+179}:\\ \;\;\;\;\left(t\_3 - t\_1\right) \cdot 0.5 - \frac{\left|q\right| \cdot \left|q\right|}{t\_1}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\frac{t\_3}{\left|q\right|}, 0.5, -1\right) \cdot \left|q\right|\\ \end{array} \]
              (FPCore (p r q)
                :precision binary64
                :pre TRUE
                (let* ((t_0 (pow (fabs q) 2.0))
                     (t_1 (fabs (- (fmin p r) (fmax p r))))
                     (t_2 (fabs (fmin p r)))
                     (t_3 (+ (fabs (fmax p r)) t_2)))
                (if (<= t_0 5e-224)
                  (fma 0.5 t_2 (* 0.5 (fmin p r)))
                  (if (<= t_0 2e+179)
                    (- (* (- t_3 t_1) 0.5) (/ (* (fabs q) (fabs q)) t_1))
                    (* (fma (/ t_3 (fabs q)) 0.5 -1.0) (fabs q))))))
              double code(double p, double r, double q) {
              	double t_0 = pow(fabs(q), 2.0);
              	double t_1 = fabs((fmin(p, r) - fmax(p, r)));
              	double t_2 = fabs(fmin(p, r));
              	double t_3 = fabs(fmax(p, r)) + t_2;
              	double tmp;
              	if (t_0 <= 5e-224) {
              		tmp = fma(0.5, t_2, (0.5 * fmin(p, r)));
              	} else if (t_0 <= 2e+179) {
              		tmp = ((t_3 - t_1) * 0.5) - ((fabs(q) * fabs(q)) / t_1);
              	} else {
              		tmp = fma((t_3 / fabs(q)), 0.5, -1.0) * fabs(q);
              	}
              	return tmp;
              }
              
              function code(p, r, q)
              	t_0 = abs(q) ^ 2.0
              	t_1 = abs(Float64(fmin(p, r) - fmax(p, r)))
              	t_2 = abs(fmin(p, r))
              	t_3 = Float64(abs(fmax(p, r)) + t_2)
              	tmp = 0.0
              	if (t_0 <= 5e-224)
              		tmp = fma(0.5, t_2, Float64(0.5 * fmin(p, r)));
              	elseif (t_0 <= 2e+179)
              		tmp = Float64(Float64(Float64(t_3 - t_1) * 0.5) - Float64(Float64(abs(q) * abs(q)) / t_1));
              	else
              		tmp = Float64(fma(Float64(t_3 / abs(q)), 0.5, -1.0) * abs(q));
              	end
              	return tmp
              end
              
              code[p_, r_, q_] := Block[{t$95$0 = N[Power[N[Abs[q], $MachinePrecision], 2.0], $MachinePrecision]}, Block[{t$95$1 = N[Abs[N[(N[Min[p, r], $MachinePrecision] - N[Max[p, r], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$2 = N[Abs[N[Min[p, r], $MachinePrecision]], $MachinePrecision]}, Block[{t$95$3 = N[(N[Abs[N[Max[p, r], $MachinePrecision]], $MachinePrecision] + t$95$2), $MachinePrecision]}, If[LessEqual[t$95$0, 5e-224], N[(0.5 * t$95$2 + N[(0.5 * N[Min[p, r], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, 2e+179], N[(N[(N[(t$95$3 - t$95$1), $MachinePrecision] * 0.5), $MachinePrecision] - N[(N[(N[Abs[q], $MachinePrecision] * N[Abs[q], $MachinePrecision]), $MachinePrecision] / t$95$1), $MachinePrecision]), $MachinePrecision], N[(N[(N[(t$95$3 / N[Abs[q], $MachinePrecision]), $MachinePrecision] * 0.5 + -1.0), $MachinePrecision] * N[Abs[q], $MachinePrecision]), $MachinePrecision]]]]]]]
              
              f(p, r, q):
              	p in [-inf, +inf],
              	r in [-inf, +inf],
              	q in [-inf, +inf]
              code: THEORY
              BEGIN
              f(p, r, q: real): real =
              	LET t_0 = ((abs(q)) ^ (2)) IN
              		LET tmp = IF (p < r) THEN p ELSE r ENDIF IN
              		LET tmp_1 = IF (p > r) THEN p ELSE r ENDIF IN
              		LET t_1 = (abs((tmp - tmp_1))) IN
              			LET tmp_2 = IF (p < r) THEN p ELSE r ENDIF IN
              			LET t_2 = (abs(tmp_2)) IN
              				LET tmp_3 = IF (p > r) THEN p ELSE r ENDIF IN
              				LET t_3 = ((abs(tmp_3)) + t_2) IN
              					LET tmp_6 = IF (p < r) THEN p ELSE r ENDIF IN
              					LET tmp_7 = IF (t_0 <= (199999999999999996091099546963028318915752778493452543828291966300228010772656544918538878468995967298844297195887900676839994006336880488768194581630088140609089562433891216654336)) THEN (((t_3 - t_1) * (5e-1)) - (((abs(q)) * (abs(q))) / t_1)) ELSE ((((t_3 / (abs(q))) * (5e-1)) + (-1)) * (abs(q))) ENDIF IN
              					LET tmp_5 = IF (t_0 <= (499999999999999985446953231405953187004000285153417599746840100991383165184323288723455329279773138643813346355731201716053364298848098380338701547237187340691844592992080114739689001542607083409411549265022024348697226710906840397444772420529571073058679206551489729134224153677729186130531955859985623877264199414009442916238742495490569493828709020342904011536226600493239142123792667615143265058502757292731879517381636236209020863797528431061698548026394597237405148362723326280011239694358499309954064432056402123608109520393194546983295367681421339511871337890625e-793)) THEN (((5e-1) * t_2) + ((5e-1) * tmp_6)) ELSE tmp_7 ENDIF IN
              	tmp_5
              END code
              \begin{array}{l}
              t_0 := {\left(\left|q\right|\right)}^{2}\\
              t_1 := \left|\mathsf{min}\left(p, r\right) - \mathsf{max}\left(p, r\right)\right|\\
              t_2 := \left|\mathsf{min}\left(p, r\right)\right|\\
              t_3 := \left|\mathsf{max}\left(p, r\right)\right| + t\_2\\
              \mathbf{if}\;t\_0 \leq 5 \cdot 10^{-224}:\\
              \;\;\;\;\mathsf{fma}\left(0.5, t\_2, 0.5 \cdot \mathsf{min}\left(p, r\right)\right)\\
              
              \mathbf{elif}\;t\_0 \leq 2 \cdot 10^{+179}:\\
              \;\;\;\;\left(t\_3 - t\_1\right) \cdot 0.5 - \frac{\left|q\right| \cdot \left|q\right|}{t\_1}\\
              
              \mathbf{else}:\\
              \;\;\;\;\mathsf{fma}\left(\frac{t\_3}{\left|q\right|}, 0.5, -1\right) \cdot \left|q\right|\\
              
              
              \end{array}
              
              Derivation
              1. Split input into 3 regimes
              2. if (pow.f64 q #s(literal 2 binary64)) < 4.9999999999999999e-224

                1. Initial program 24.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. Applied rewrites21.7%

                  \[\leadsto \mathsf{fma}\left(0.5, \left|p\right|, \left(\left|r\right| - \sqrt{\mathsf{fma}\left(q \cdot q, 4, \left(p - r\right) \cdot \left(p - r\right)\right)}\right) \cdot 0.5\right) \]
                3. Taylor expanded in p around -inf

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

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

                  if 4.9999999999999999e-224 < (pow.f64 q #s(literal 2 binary64)) < 2e179

                  1. Initial program 24.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. Taylor expanded in q around 0

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

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

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

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

                    1. Initial program 24.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. Taylor expanded in q around inf

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

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

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

                      Alternative 4: 56.8% accurate, 1.6× speedup?

                      \[\begin{array}{l} \mathbf{if}\;{\left(\left|q\right|\right)}^{2} \leq 2 \cdot 10^{-38}:\\ \;\;\;\;\mathsf{fma}\left(0.5, \left|\mathsf{min}\left(p, r\right)\right|, 0.5 \cdot \mathsf{min}\left(p, r\right)\right)\\ \mathbf{else}:\\ \;\;\;\;-\left|q\right|\\ \end{array} \]
                      (FPCore (p r q)
                        :precision binary64
                        :pre TRUE
                        (if (<= (pow (fabs q) 2.0) 2e-38)
                        (fma 0.5 (fabs (fmin p r)) (* 0.5 (fmin p r)))
                        (- (fabs q))))
                      double code(double p, double r, double q) {
                      	double tmp;
                      	if (pow(fabs(q), 2.0) <= 2e-38) {
                      		tmp = fma(0.5, fabs(fmin(p, r)), (0.5 * fmin(p, r)));
                      	} else {
                      		tmp = -fabs(q);
                      	}
                      	return tmp;
                      }
                      
                      function code(p, r, q)
                      	tmp = 0.0
                      	if ((abs(q) ^ 2.0) <= 2e-38)
                      		tmp = fma(0.5, abs(fmin(p, r)), Float64(0.5 * fmin(p, r)));
                      	else
                      		tmp = Float64(-abs(q));
                      	end
                      	return tmp
                      end
                      
                      code[p_, r_, q_] := If[LessEqual[N[Power[N[Abs[q], $MachinePrecision], 2.0], $MachinePrecision], 2e-38], N[(0.5 * N[Abs[N[Min[p, r], $MachinePrecision]], $MachinePrecision] + N[(0.5 * N[Min[p, r], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], (-N[Abs[q], $MachinePrecision])]
                      
                      f(p, r, q):
                      	p in [-inf, +inf],
                      	r in [-inf, +inf],
                      	q in [-inf, +inf]
                      code: THEORY
                      BEGIN
                      f(p, r, q: real): real =
                      	LET tmp_3 = IF (p < r) THEN p ELSE r ENDIF IN
                      	LET tmp_4 = IF (p < r) THEN p ELSE r ENDIF IN
                      	LET tmp_2 = IF (((abs(q)) ^ (2)) <= (1999999999999999923838803479745535271764231330689422904974307025153525577488581767005427746518677646625494759291541413404047489166259765625e-176)) THEN (((5e-1) * (abs(tmp_3))) + ((5e-1) * tmp_4)) ELSE (- (abs(q))) ENDIF IN
                      	tmp_2
                      END code
                      \begin{array}{l}
                      \mathbf{if}\;{\left(\left|q\right|\right)}^{2} \leq 2 \cdot 10^{-38}:\\
                      \;\;\;\;\mathsf{fma}\left(0.5, \left|\mathsf{min}\left(p, r\right)\right|, 0.5 \cdot \mathsf{min}\left(p, r\right)\right)\\
                      
                      \mathbf{else}:\\
                      \;\;\;\;-\left|q\right|\\
                      
                      
                      \end{array}
                      
                      Derivation
                      1. Split input into 2 regimes
                      2. if (pow.f64 q #s(literal 2 binary64)) < 1.9999999999999999e-38

                        1. Initial program 24.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. Applied rewrites21.7%

                          \[\leadsto \mathsf{fma}\left(0.5, \left|p\right|, \left(\left|r\right| - \sqrt{\mathsf{fma}\left(q \cdot q, 4, \left(p - r\right) \cdot \left(p - r\right)\right)}\right) \cdot 0.5\right) \]
                        3. Taylor expanded in p around -inf

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

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

                          if 1.9999999999999999e-38 < (pow.f64 q #s(literal 2 binary64))

                          1. Initial program 24.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. Taylor expanded in q around inf

                            \[\leadsto -1 \cdot q \]
                          3. Step-by-step derivation
                            1. Applied rewrites18.8%

                              \[\leadsto -1 \cdot q \]
                            2. Step-by-step derivation
                              1. Applied rewrites18.8%

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

                            Alternative 5: 56.8% accurate, 1.7× speedup?

                            \[\begin{array}{l} \mathbf{if}\;{\left(\left|q\right|\right)}^{2} \leq 5 \cdot 10^{-33}:\\ \;\;\;\;0.5 \cdot \left(\left|\mathsf{max}\left(p, r\right)\right| - \mathsf{max}\left(p, r\right)\right)\\ \mathbf{else}:\\ \;\;\;\;-\left|q\right|\\ \end{array} \]
                            (FPCore (p r q)
                              :precision binary64
                              :pre TRUE
                              (if (<= (pow (fabs q) 2.0) 5e-33)
                              (* 0.5 (- (fabs (fmax p r)) (fmax p r)))
                              (- (fabs q))))
                            double code(double p, double r, double q) {
                            	double tmp;
                            	if (pow(fabs(q), 2.0) <= 5e-33) {
                            		tmp = 0.5 * (fabs(fmax(p, r)) - fmax(p, r));
                            	} else {
                            		tmp = -fabs(q);
                            	}
                            	return tmp;
                            }
                            
                            real(8) function code(p, r, q)
                            use fmin_fmax_functions
                                real(8), intent (in) :: p
                                real(8), intent (in) :: r
                                real(8), intent (in) :: q
                                real(8) :: tmp
                                if ((abs(q) ** 2.0d0) <= 5d-33) then
                                    tmp = 0.5d0 * (abs(fmax(p, r)) - fmax(p, r))
                                else
                                    tmp = -abs(q)
                                end if
                                code = tmp
                            end function
                            
                            public static double code(double p, double r, double q) {
                            	double tmp;
                            	if (Math.pow(Math.abs(q), 2.0) <= 5e-33) {
                            		tmp = 0.5 * (Math.abs(fmax(p, r)) - fmax(p, r));
                            	} else {
                            		tmp = -Math.abs(q);
                            	}
                            	return tmp;
                            }
                            
                            def code(p, r, q):
                            	tmp = 0
                            	if math.pow(math.fabs(q), 2.0) <= 5e-33:
                            		tmp = 0.5 * (math.fabs(fmax(p, r)) - fmax(p, r))
                            	else:
                            		tmp = -math.fabs(q)
                            	return tmp
                            
                            function code(p, r, q)
                            	tmp = 0.0
                            	if ((abs(q) ^ 2.0) <= 5e-33)
                            		tmp = Float64(0.5 * Float64(abs(fmax(p, r)) - fmax(p, r)));
                            	else
                            		tmp = Float64(-abs(q));
                            	end
                            	return tmp
                            end
                            
                            function tmp_2 = code(p, r, q)
                            	tmp = 0.0;
                            	if ((abs(q) ^ 2.0) <= 5e-33)
                            		tmp = 0.5 * (abs(max(p, r)) - max(p, r));
                            	else
                            		tmp = -abs(q);
                            	end
                            	tmp_2 = tmp;
                            end
                            
                            code[p_, r_, q_] := If[LessEqual[N[Power[N[Abs[q], $MachinePrecision], 2.0], $MachinePrecision], 5e-33], N[(0.5 * N[(N[Abs[N[Max[p, r], $MachinePrecision]], $MachinePrecision] - N[Max[p, r], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], (-N[Abs[q], $MachinePrecision])]
                            
                            f(p, r, q):
                            	p in [-inf, +inf],
                            	r in [-inf, +inf],
                            	q in [-inf, +inf]
                            code: THEORY
                            BEGIN
                            f(p, r, q: real): real =
                            	LET tmp_3 = IF (p > r) THEN p ELSE r ENDIF IN
                            	LET tmp_4 = IF (p > r) THEN p ELSE r ENDIF IN
                            	LET tmp_2 = IF (((abs(q)) ^ (2)) <= (50000000000000002798365498812095096722612130161874003164844686563658192413998319444837052649699415951545233838260173797607421875e-160)) THEN ((5e-1) * ((abs(tmp_3)) - tmp_4)) ELSE (- (abs(q))) ENDIF IN
                            	tmp_2
                            END code
                            \begin{array}{l}
                            \mathbf{if}\;{\left(\left|q\right|\right)}^{2} \leq 5 \cdot 10^{-33}:\\
                            \;\;\;\;0.5 \cdot \left(\left|\mathsf{max}\left(p, r\right)\right| - \mathsf{max}\left(p, r\right)\right)\\
                            
                            \mathbf{else}:\\
                            \;\;\;\;-\left|q\right|\\
                            
                            
                            \end{array}
                            
                            Derivation
                            1. Split input into 2 regimes
                            2. if (pow.f64 q #s(literal 2 binary64)) < 5.0000000000000003e-33

                              1. Initial program 24.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. Step-by-step derivation
                                1. Applied rewrites23.5%

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

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

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

                                  if 5.0000000000000003e-33 < (pow.f64 q #s(literal 2 binary64))

                                  1. Initial program 24.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. Taylor expanded in q around inf

                                    \[\leadsto -1 \cdot q \]
                                  3. Step-by-step derivation
                                    1. Applied rewrites18.8%

                                      \[\leadsto -1 \cdot q \]
                                    2. Step-by-step derivation
                                      1. Applied rewrites18.8%

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

                                    Alternative 6: 35.1% accurate, 19.7× speedup?

                                    \[-\left|q\right| \]
                                    (FPCore (p r q)
                                      :precision binary64
                                      :pre TRUE
                                      (- (fabs q)))
                                    double code(double p, double r, double q) {
                                    	return -fabs(q);
                                    }
                                    
                                    real(8) function code(p, r, q)
                                    use fmin_fmax_functions
                                        real(8), intent (in) :: p
                                        real(8), intent (in) :: r
                                        real(8), intent (in) :: q
                                        code = -abs(q)
                                    end function
                                    
                                    public static double code(double p, double r, double q) {
                                    	return -Math.abs(q);
                                    }
                                    
                                    def code(p, r, q):
                                    	return -math.fabs(q)
                                    
                                    function code(p, r, q)
                                    	return Float64(-abs(q))
                                    end
                                    
                                    function tmp = code(p, r, q)
                                    	tmp = -abs(q);
                                    end
                                    
                                    code[p_, r_, q_] := (-N[Abs[q], $MachinePrecision])
                                    
                                    f(p, r, q):
                                    	p in [-inf, +inf],
                                    	r in [-inf, +inf],
                                    	q in [-inf, +inf]
                                    code: THEORY
                                    BEGIN
                                    f(p, r, q: real): real =
                                    	- (abs(q))
                                    END code
                                    -\left|q\right|
                                    
                                    Derivation
                                    1. Initial program 24.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. Taylor expanded in q around inf

                                      \[\leadsto -1 \cdot q \]
                                    3. Step-by-step derivation
                                      1. Applied rewrites18.8%

                                        \[\leadsto -1 \cdot q \]
                                      2. Step-by-step derivation
                                        1. Applied rewrites18.8%

                                          \[\leadsto -q \]
                                        2. Add Preprocessing

                                        Reproduce

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