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

Percentage Accurate: 24.7% → 73.7%
Time: 7.4s
Alternatives: 7
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 7 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?

\[\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: 73.7% accurate, 1.4× speedup?

\[\begin{array}{l} t_0 := \left|\mathsf{max}\left(p, r\right)\right|\\ t_1 := \left|\mathsf{min}\left(p, r\right)\right|\\ \mathbf{if}\;\mathsf{min}\left(p, r\right) \leq -3.937797594432574 \cdot 10^{+110}:\\ \;\;\;\;\mathsf{fma}\left(t\_0 - \mathsf{max}\left(p, r\right), 0.5, \frac{\left|q\right|}{\frac{\mathsf{min}\left(p, r\right)}{\left|q\right|}}\right)\\ \mathbf{elif}\;\mathsf{min}\left(p, r\right) \leq 8.005172054124462 \cdot 10^{-282}:\\ \;\;\;\;\frac{1}{\frac{\mathsf{fma}\left(\frac{t\_0 + t\_1}{\left|q\right|}, -0.5, -1\right)}{\left|q\right|}}\\ \mathbf{else}:\\ \;\;\;\;\left(t\_1 + \mathsf{min}\left(p, r\right)\right) \cdot 0.5 - \left|q\right| \cdot \frac{\left|q\right|}{\mathsf{max}\left(p, r\right)}\\ \end{array} \]
(FPCore (p r q)
  :precision binary64
  :pre TRUE
  (let* ((t_0 (fabs (fmax p r))) (t_1 (fabs (fmin p r))))
  (if (<= (fmin p r) -3.937797594432574e+110)
    (fma (- t_0 (fmax p r)) 0.5 (/ (fabs q) (/ (fmin p r) (fabs q))))
    (if (<= (fmin p r) 8.005172054124462e-282)
      (/ 1.0 (/ (fma (/ (+ t_0 t_1) (fabs q)) -0.5 -1.0) (fabs q)))
      (-
       (* (+ t_1 (fmin p r)) 0.5)
       (* (fabs q) (/ (fabs q) (fmax p r))))))))
double code(double p, double r, double q) {
	double t_0 = fabs(fmax(p, r));
	double t_1 = fabs(fmin(p, r));
	double tmp;
	if (fmin(p, r) <= -3.937797594432574e+110) {
		tmp = fma((t_0 - fmax(p, r)), 0.5, (fabs(q) / (fmin(p, r) / fabs(q))));
	} else if (fmin(p, r) <= 8.005172054124462e-282) {
		tmp = 1.0 / (fma(((t_0 + t_1) / fabs(q)), -0.5, -1.0) / fabs(q));
	} else {
		tmp = ((t_1 + fmin(p, r)) * 0.5) - (fabs(q) * (fabs(q) / fmax(p, r)));
	}
	return tmp;
}
function code(p, r, q)
	t_0 = abs(fmax(p, r))
	t_1 = abs(fmin(p, r))
	tmp = 0.0
	if (fmin(p, r) <= -3.937797594432574e+110)
		tmp = fma(Float64(t_0 - fmax(p, r)), 0.5, Float64(abs(q) / Float64(fmin(p, r) / abs(q))));
	elseif (fmin(p, r) <= 8.005172054124462e-282)
		tmp = Float64(1.0 / Float64(fma(Float64(Float64(t_0 + t_1) / abs(q)), -0.5, -1.0) / abs(q)));
	else
		tmp = Float64(Float64(Float64(t_1 + fmin(p, r)) * 0.5) - Float64(abs(q) * Float64(abs(q) / fmax(p, r))));
	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[Abs[N[Min[p, r], $MachinePrecision]], $MachinePrecision]}, If[LessEqual[N[Min[p, r], $MachinePrecision], -3.937797594432574e+110], N[(N[(t$95$0 - N[Max[p, r], $MachinePrecision]), $MachinePrecision] * 0.5 + N[(N[Abs[q], $MachinePrecision] / N[(N[Min[p, r], $MachinePrecision] / N[Abs[q], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[Min[p, r], $MachinePrecision], 8.005172054124462e-282], N[(1.0 / N[(N[(N[(N[(t$95$0 + t$95$1), $MachinePrecision] / N[Abs[q], $MachinePrecision]), $MachinePrecision] * -0.5 + -1.0), $MachinePrecision] / N[Abs[q], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(t$95$1 + N[Min[p, r], $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision] - N[(N[Abs[q], $MachinePrecision] * N[(N[Abs[q], $MachinePrecision] / N[Max[p, r], $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 =
	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 t_1 = (abs(tmp_1)) IN
			LET tmp_5 = IF (p < r) THEN p ELSE r ENDIF IN
			LET tmp_6 = IF (p > r) THEN p ELSE r ENDIF IN
			LET tmp_7 = IF (p < r) THEN p ELSE r ENDIF IN
			LET tmp_9 = IF (p < r) THEN p ELSE r ENDIF IN
			LET tmp_10 = IF (p < r) THEN p ELSE r ENDIF IN
			LET tmp_11 = IF (p > r) THEN p ELSE r ENDIF IN
			LET tmp_8 = IF (tmp_9 <= (800517205412446219477454536431108565466765951142374412918650977149136070947084886256878407365805903999240477628715985601775360427880646360764815851440591113896638864256591326383668997601666073357439545600548703873687936997278673716983858223944068442708144470090620044593163107879457995338084079558342812651708751422679820400495875000297240284840584872065147561548088061614887628815800684503365867702404563085705981219572695270097522973492233456728126255935235963252893350172287652141939195014279412200269512257397228072627513038586102305944640421892445661880073174147245366326311638154076817722035216876895167235571953413472125230035736487163424518992233166393593206400236539366233046166598796844482421875e-986)) THEN ((1) / (((((t_0 + t_1) / (abs(q))) * (-5e-1)) + (-1)) / (abs(q)))) ELSE (((t_1 + tmp_10) * (5e-1)) - ((abs(q)) * ((abs(q)) / tmp_11))) ENDIF IN
			LET tmp_4 = IF (tmp_5 <= (-393779759443257386101137661258281232848298910811689396281032690547950041627557607840495675257016259267199500288)) THEN (((t_0 - tmp_6) * (5e-1)) + ((abs(q)) / (tmp_7 / (abs(q))))) ELSE tmp_8 ENDIF IN
	tmp_4
END code
\begin{array}{l}
t_0 := \left|\mathsf{max}\left(p, r\right)\right|\\
t_1 := \left|\mathsf{min}\left(p, r\right)\right|\\
\mathbf{if}\;\mathsf{min}\left(p, r\right) \leq -3.937797594432574 \cdot 10^{+110}:\\
\;\;\;\;\mathsf{fma}\left(t\_0 - \mathsf{max}\left(p, r\right), 0.5, \frac{\left|q\right|}{\frac{\mathsf{min}\left(p, r\right)}{\left|q\right|}}\right)\\

\mathbf{elif}\;\mathsf{min}\left(p, r\right) \leq 8.005172054124462 \cdot 10^{-282}:\\
\;\;\;\;\frac{1}{\frac{\mathsf{fma}\left(\frac{t\_0 + t\_1}{\left|q\right|}, -0.5, -1\right)}{\left|q\right|}}\\

\mathbf{else}:\\
\;\;\;\;\left(t\_1 + \mathsf{min}\left(p, r\right)\right) \cdot 0.5 - \left|q\right| \cdot \frac{\left|q\right|}{\mathsf{max}\left(p, r\right)}\\


\end{array}
Derivation
  1. Split input into 3 regimes
  2. if p < -3.9377975944325739e110

    1. Initial program 24.7%

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

        \[\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) + \frac{{q}^{2}}{p} \]
      3. Step-by-step derivation
        1. Applied rewrites20.3%

          \[\leadsto \mathsf{fma}\left(0.5, \left|r\right| - r, \frac{{q}^{2}}{p}\right) \]
        2. Applied rewrites20.3%

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

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

          if -3.9377975944325739e110 < p < 8.0051720541244622e-282

          1. Initial program 24.7%

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

              \[\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 rewrites38.2%

              \[\leadsto \frac{1}{{\left(\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|}\right)}^{-1}} \]
            3. Taylor expanded in q around inf

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

                \[\leadsto \frac{1}{\frac{-0.5 \cdot \frac{\left|p\right| + \left|r\right|}{q} - 1}{q}} \]
              2. Applied rewrites38.7%

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

              if 8.0051720541244622e-282 < p

              1. Initial program 24.7%

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

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

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

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

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

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

                  Alternative 2: 64.5% accurate, 1.4× speedup?

                  \[\begin{array}{l} \mathbf{if}\;\mathsf{min}\left(p, r\right) \leq -1.0317428604104856 \cdot 10^{+52}:\\ \;\;\;\;\mathsf{fma}\left(\left|\mathsf{max}\left(p, r\right)\right| - \mathsf{max}\left(p, r\right), 0.5, \frac{\left|q\right|}{\frac{\mathsf{min}\left(p, r\right)}{\left|q\right|}}\right)\\ \mathbf{elif}\;\mathsf{min}\left(p, r\right) \leq 8.005172054124462 \cdot 10^{-282}:\\ \;\;\;\;-\left|q\right|\\ \mathbf{else}:\\ \;\;\;\;\left(\left|\mathsf{min}\left(p, r\right)\right| + \mathsf{min}\left(p, r\right)\right) \cdot 0.5 - \left|q\right| \cdot \frac{\left|q\right|}{\mathsf{max}\left(p, r\right)}\\ \end{array} \]
                  (FPCore (p r q)
                    :precision binary64
                    :pre TRUE
                    (if (<= (fmin p r) -1.0317428604104856e+52)
                    (fma
                     (- (fabs (fmax p r)) (fmax p r))
                     0.5
                     (/ (fabs q) (/ (fmin p r) (fabs q))))
                    (if (<= (fmin p r) 8.005172054124462e-282)
                      (- (fabs q))
                      (-
                       (* (+ (fabs (fmin p r)) (fmin p r)) 0.5)
                       (* (fabs q) (/ (fabs q) (fmax p r)))))))
                  double code(double p, double r, double q) {
                  	double tmp;
                  	if (fmin(p, r) <= -1.0317428604104856e+52) {
                  		tmp = fma((fabs(fmax(p, r)) - fmax(p, r)), 0.5, (fabs(q) / (fmin(p, r) / fabs(q))));
                  	} else if (fmin(p, r) <= 8.005172054124462e-282) {
                  		tmp = -fabs(q);
                  	} else {
                  		tmp = ((fabs(fmin(p, r)) + fmin(p, r)) * 0.5) - (fabs(q) * (fabs(q) / fmax(p, r)));
                  	}
                  	return tmp;
                  }
                  
                  function code(p, r, q)
                  	tmp = 0.0
                  	if (fmin(p, r) <= -1.0317428604104856e+52)
                  		tmp = fma(Float64(abs(fmax(p, r)) - fmax(p, r)), 0.5, Float64(abs(q) / Float64(fmin(p, r) / abs(q))));
                  	elseif (fmin(p, r) <= 8.005172054124462e-282)
                  		tmp = Float64(-abs(q));
                  	else
                  		tmp = Float64(Float64(Float64(abs(fmin(p, r)) + fmin(p, r)) * 0.5) - Float64(abs(q) * Float64(abs(q) / fmax(p, r))));
                  	end
                  	return tmp
                  end
                  
                  code[p_, r_, q_] := If[LessEqual[N[Min[p, r], $MachinePrecision], -1.0317428604104856e+52], N[(N[(N[Abs[N[Max[p, r], $MachinePrecision]], $MachinePrecision] - N[Max[p, r], $MachinePrecision]), $MachinePrecision] * 0.5 + N[(N[Abs[q], $MachinePrecision] / N[(N[Min[p, r], $MachinePrecision] / N[Abs[q], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[Min[p, r], $MachinePrecision], 8.005172054124462e-282], (-N[Abs[q], $MachinePrecision]), N[(N[(N[(N[Abs[N[Min[p, r], $MachinePrecision]], $MachinePrecision] + N[Min[p, r], $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision] - N[(N[Abs[q], $MachinePrecision] * N[(N[Abs[q], $MachinePrecision] / N[Max[p, r], $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 =
                  	LET tmp_4 = IF (p < r) THEN p ELSE r ENDIF IN
                  	LET tmp_5 = IF (p > r) THEN p ELSE r ENDIF IN
                  	LET tmp_6 = IF (p > r) THEN p ELSE r ENDIF IN
                  	LET tmp_7 = IF (p < r) THEN p ELSE r ENDIF IN
                  	LET tmp_9 = IF (p < r) THEN p ELSE r ENDIF IN
                  	LET tmp_10 = IF (p < r) THEN p ELSE r ENDIF IN
                  	LET tmp_11 = IF (p < r) THEN p ELSE r ENDIF IN
                  	LET tmp_12 = IF (p > r) THEN p ELSE r ENDIF IN
                  	LET tmp_8 = IF (tmp_9 <= (800517205412446219477454536431108565466765951142374412918650977149136070947084886256878407365805903999240477628715985601775360427880646360764815851440591113896638864256591326383668997601666073357439545600548703873687936997278673716983858223944068442708144470090620044593163107879457995338084079558342812651708751422679820400495875000297240284840584872065147561548088061614887628815800684503365867702404563085705981219572695270097522973492233456728126255935235963252893350172287652141939195014279412200269512257397228072627513038586102305944640421892445661880073174147245366326311638154076817722035216876895167235571953413472125230035736487163424518992233166393593206400236539366233046166598796844482421875e-986)) THEN (- (abs(q))) ELSE ((((abs(tmp_10)) + tmp_11) * (5e-1)) - ((abs(q)) * ((abs(q)) / tmp_12))) ENDIF IN
                  	LET tmp_3 = IF (tmp_4 <= (-10317428604104855837448523736291688882839200227917824)) THEN ((((abs(tmp_5)) - tmp_6) * (5e-1)) + ((abs(q)) / (tmp_7 / (abs(q))))) ELSE tmp_8 ENDIF IN
                  	tmp_3
                  END code
                  \begin{array}{l}
                  \mathbf{if}\;\mathsf{min}\left(p, r\right) \leq -1.0317428604104856 \cdot 10^{+52}:\\
                  \;\;\;\;\mathsf{fma}\left(\left|\mathsf{max}\left(p, r\right)\right| - \mathsf{max}\left(p, r\right), 0.5, \frac{\left|q\right|}{\frac{\mathsf{min}\left(p, r\right)}{\left|q\right|}}\right)\\
                  
                  \mathbf{elif}\;\mathsf{min}\left(p, r\right) \leq 8.005172054124462 \cdot 10^{-282}:\\
                  \;\;\;\;-\left|q\right|\\
                  
                  \mathbf{else}:\\
                  \;\;\;\;\left(\left|\mathsf{min}\left(p, r\right)\right| + \mathsf{min}\left(p, r\right)\right) \cdot 0.5 - \left|q\right| \cdot \frac{\left|q\right|}{\mathsf{max}\left(p, r\right)}\\
                  
                  
                  \end{array}
                  
                  Derivation
                  1. Split input into 3 regimes
                  2. if p < -1.0317428604104856e52

                    1. Initial program 24.7%

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

                        \[\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) + \frac{{q}^{2}}{p} \]
                      3. Step-by-step derivation
                        1. Applied rewrites20.3%

                          \[\leadsto \mathsf{fma}\left(0.5, \left|r\right| - r, \frac{{q}^{2}}{p}\right) \]
                        2. Applied rewrites20.3%

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

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

                          if -1.0317428604104856e52 < p < 8.0051720541244622e-282

                          1. Initial program 24.7%

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

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

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

                                \[\leadsto -q \]

                              if 8.0051720541244622e-282 < p

                              1. Initial program 24.7%

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

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

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

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

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

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

                                  Alternative 3: 64.5% accurate, 1.4× speedup?

                                  \[\begin{array}{l} \mathbf{if}\;\mathsf{min}\left(p, r\right) \leq -1.0317428604104856 \cdot 10^{+52}:\\ \;\;\;\;\mathsf{fma}\left(\left|\mathsf{max}\left(p, r\right)\right| - \mathsf{max}\left(p, r\right), 0.5, \left|q\right| \cdot \frac{\left|q\right|}{\mathsf{min}\left(p, r\right)}\right)\\ \mathbf{elif}\;\mathsf{min}\left(p, r\right) \leq 8.005172054124462 \cdot 10^{-282}:\\ \;\;\;\;-\left|q\right|\\ \mathbf{else}:\\ \;\;\;\;\left(\left|\mathsf{min}\left(p, r\right)\right| + \mathsf{min}\left(p, r\right)\right) \cdot 0.5 - \left|q\right| \cdot \frac{\left|q\right|}{\mathsf{max}\left(p, r\right)}\\ \end{array} \]
                                  (FPCore (p r q)
                                    :precision binary64
                                    :pre TRUE
                                    (if (<= (fmin p r) -1.0317428604104856e+52)
                                    (fma
                                     (- (fabs (fmax p r)) (fmax p r))
                                     0.5
                                     (* (fabs q) (/ (fabs q) (fmin p r))))
                                    (if (<= (fmin p r) 8.005172054124462e-282)
                                      (- (fabs q))
                                      (-
                                       (* (+ (fabs (fmin p r)) (fmin p r)) 0.5)
                                       (* (fabs q) (/ (fabs q) (fmax p r)))))))
                                  double code(double p, double r, double q) {
                                  	double tmp;
                                  	if (fmin(p, r) <= -1.0317428604104856e+52) {
                                  		tmp = fma((fabs(fmax(p, r)) - fmax(p, r)), 0.5, (fabs(q) * (fabs(q) / fmin(p, r))));
                                  	} else if (fmin(p, r) <= 8.005172054124462e-282) {
                                  		tmp = -fabs(q);
                                  	} else {
                                  		tmp = ((fabs(fmin(p, r)) + fmin(p, r)) * 0.5) - (fabs(q) * (fabs(q) / fmax(p, r)));
                                  	}
                                  	return tmp;
                                  }
                                  
                                  function code(p, r, q)
                                  	tmp = 0.0
                                  	if (fmin(p, r) <= -1.0317428604104856e+52)
                                  		tmp = fma(Float64(abs(fmax(p, r)) - fmax(p, r)), 0.5, Float64(abs(q) * Float64(abs(q) / fmin(p, r))));
                                  	elseif (fmin(p, r) <= 8.005172054124462e-282)
                                  		tmp = Float64(-abs(q));
                                  	else
                                  		tmp = Float64(Float64(Float64(abs(fmin(p, r)) + fmin(p, r)) * 0.5) - Float64(abs(q) * Float64(abs(q) / fmax(p, r))));
                                  	end
                                  	return tmp
                                  end
                                  
                                  code[p_, r_, q_] := If[LessEqual[N[Min[p, r], $MachinePrecision], -1.0317428604104856e+52], N[(N[(N[Abs[N[Max[p, r], $MachinePrecision]], $MachinePrecision] - N[Max[p, r], $MachinePrecision]), $MachinePrecision] * 0.5 + N[(N[Abs[q], $MachinePrecision] * N[(N[Abs[q], $MachinePrecision] / N[Min[p, r], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[Min[p, r], $MachinePrecision], 8.005172054124462e-282], (-N[Abs[q], $MachinePrecision]), N[(N[(N[(N[Abs[N[Min[p, r], $MachinePrecision]], $MachinePrecision] + N[Min[p, r], $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision] - N[(N[Abs[q], $MachinePrecision] * N[(N[Abs[q], $MachinePrecision] / N[Max[p, r], $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 =
                                  	LET tmp_4 = IF (p < r) THEN p ELSE r ENDIF IN
                                  	LET tmp_5 = IF (p > r) THEN p ELSE r ENDIF IN
                                  	LET tmp_6 = IF (p > r) THEN p ELSE r ENDIF IN
                                  	LET tmp_7 = IF (p < r) THEN p ELSE r ENDIF IN
                                  	LET tmp_9 = IF (p < r) THEN p ELSE r ENDIF IN
                                  	LET tmp_10 = IF (p < r) THEN p ELSE r ENDIF IN
                                  	LET tmp_11 = IF (p < r) THEN p ELSE r ENDIF IN
                                  	LET tmp_12 = IF (p > r) THEN p ELSE r ENDIF IN
                                  	LET tmp_8 = IF (tmp_9 <= (800517205412446219477454536431108565466765951142374412918650977149136070947084886256878407365805903999240477628715985601775360427880646360764815851440591113896638864256591326383668997601666073357439545600548703873687936997278673716983858223944068442708144470090620044593163107879457995338084079558342812651708751422679820400495875000297240284840584872065147561548088061614887628815800684503365867702404563085705981219572695270097522973492233456728126255935235963252893350172287652141939195014279412200269512257397228072627513038586102305944640421892445661880073174147245366326311638154076817722035216876895167235571953413472125230035736487163424518992233166393593206400236539366233046166598796844482421875e-986)) THEN (- (abs(q))) ELSE ((((abs(tmp_10)) + tmp_11) * (5e-1)) - ((abs(q)) * ((abs(q)) / tmp_12))) ENDIF IN
                                  	LET tmp_3 = IF (tmp_4 <= (-10317428604104855837448523736291688882839200227917824)) THEN ((((abs(tmp_5)) - tmp_6) * (5e-1)) + ((abs(q)) * ((abs(q)) / tmp_7))) ELSE tmp_8 ENDIF IN
                                  	tmp_3
                                  END code
                                  \begin{array}{l}
                                  \mathbf{if}\;\mathsf{min}\left(p, r\right) \leq -1.0317428604104856 \cdot 10^{+52}:\\
                                  \;\;\;\;\mathsf{fma}\left(\left|\mathsf{max}\left(p, r\right)\right| - \mathsf{max}\left(p, r\right), 0.5, \left|q\right| \cdot \frac{\left|q\right|}{\mathsf{min}\left(p, r\right)}\right)\\
                                  
                                  \mathbf{elif}\;\mathsf{min}\left(p, r\right) \leq 8.005172054124462 \cdot 10^{-282}:\\
                                  \;\;\;\;-\left|q\right|\\
                                  
                                  \mathbf{else}:\\
                                  \;\;\;\;\left(\left|\mathsf{min}\left(p, r\right)\right| + \mathsf{min}\left(p, r\right)\right) \cdot 0.5 - \left|q\right| \cdot \frac{\left|q\right|}{\mathsf{max}\left(p, r\right)}\\
                                  
                                  
                                  \end{array}
                                  
                                  Derivation
                                  1. Split input into 3 regimes
                                  2. if p < -1.0317428604104856e52

                                    1. Initial program 24.7%

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

                                        \[\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) + \frac{{q}^{2}}{p} \]
                                      3. Step-by-step derivation
                                        1. Applied rewrites20.3%

                                          \[\leadsto \mathsf{fma}\left(0.5, \left|r\right| - r, \frac{{q}^{2}}{p}\right) \]
                                        2. Applied rewrites20.3%

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

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

                                          if -1.0317428604104856e52 < p < 8.0051720541244622e-282

                                          1. Initial program 24.7%

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

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

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

                                                \[\leadsto -q \]

                                              if 8.0051720541244622e-282 < p

                                              1. Initial program 24.7%

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

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

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

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

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

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

                                                  Alternative 4: 61.5% accurate, 1.7× speedup?

                                                  \[\begin{array}{l} \mathbf{if}\;\mathsf{min}\left(p, r\right) \leq -1.0317428604104856 \cdot 10^{+52}:\\ \;\;\;\;\mathsf{fma}\left(\left|\mathsf{max}\left(p, r\right)\right| - \mathsf{max}\left(p, r\right), 0.5, \left|q\right| \cdot \frac{\left|q\right|}{\mathsf{min}\left(p, r\right)}\right)\\ \mathbf{elif}\;\mathsf{min}\left(p, r\right) \leq 3.799500869048362 \cdot 10^{-86}:\\ \;\;\;\;-\left|q\right|\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \left(\mathsf{min}\left(p, r\right) + \left|\mathsf{min}\left(p, r\right)\right|\right)\\ \end{array} \]
                                                  (FPCore (p r q)
                                                    :precision binary64
                                                    :pre TRUE
                                                    (if (<= (fmin p r) -1.0317428604104856e+52)
                                                    (fma
                                                     (- (fabs (fmax p r)) (fmax p r))
                                                     0.5
                                                     (* (fabs q) (/ (fabs q) (fmin p r))))
                                                    (if (<= (fmin p r) 3.799500869048362e-86)
                                                      (- (fabs q))
                                                      (* 0.5 (+ (fmin p r) (fabs (fmin p r)))))))
                                                  double code(double p, double r, double q) {
                                                  	double tmp;
                                                  	if (fmin(p, r) <= -1.0317428604104856e+52) {
                                                  		tmp = fma((fabs(fmax(p, r)) - fmax(p, r)), 0.5, (fabs(q) * (fabs(q) / fmin(p, r))));
                                                  	} else if (fmin(p, r) <= 3.799500869048362e-86) {
                                                  		tmp = -fabs(q);
                                                  	} else {
                                                  		tmp = 0.5 * (fmin(p, r) + fabs(fmin(p, r)));
                                                  	}
                                                  	return tmp;
                                                  }
                                                  
                                                  function code(p, r, q)
                                                  	tmp = 0.0
                                                  	if (fmin(p, r) <= -1.0317428604104856e+52)
                                                  		tmp = fma(Float64(abs(fmax(p, r)) - fmax(p, r)), 0.5, Float64(abs(q) * Float64(abs(q) / fmin(p, r))));
                                                  	elseif (fmin(p, r) <= 3.799500869048362e-86)
                                                  		tmp = Float64(-abs(q));
                                                  	else
                                                  		tmp = Float64(0.5 * Float64(fmin(p, r) + abs(fmin(p, r))));
                                                  	end
                                                  	return tmp
                                                  end
                                                  
                                                  code[p_, r_, q_] := If[LessEqual[N[Min[p, r], $MachinePrecision], -1.0317428604104856e+52], N[(N[(N[Abs[N[Max[p, r], $MachinePrecision]], $MachinePrecision] - N[Max[p, r], $MachinePrecision]), $MachinePrecision] * 0.5 + N[(N[Abs[q], $MachinePrecision] * N[(N[Abs[q], $MachinePrecision] / N[Min[p, r], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[Min[p, r], $MachinePrecision], 3.799500869048362e-86], (-N[Abs[q], $MachinePrecision]), N[(0.5 * N[(N[Min[p, r], $MachinePrecision] + N[Abs[N[Min[p, r], $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 =
                                                  	LET tmp_4 = IF (p < r) THEN p ELSE r ENDIF IN
                                                  	LET tmp_5 = IF (p > r) THEN p ELSE r ENDIF IN
                                                  	LET tmp_6 = IF (p > r) THEN p ELSE r ENDIF IN
                                                  	LET tmp_7 = IF (p < r) THEN p ELSE r ENDIF IN
                                                  	LET tmp_9 = IF (p < r) THEN p ELSE r ENDIF IN
                                                  	LET tmp_10 = IF (p < r) THEN p ELSE r ENDIF IN
                                                  	LET tmp_11 = IF (p < r) THEN p ELSE r ENDIF IN
                                                  	LET tmp_8 = IF (tmp_9 <= (37995008690483622742517593840024996725558567468836356603656494418637975745005523357760279920254242100828511083706611991164679125227866292501805017156370792894805272258189959420593666351939783527097045665176671715157485920144608826376497745513916015625e-336)) THEN (- (abs(q))) ELSE ((5e-1) * (tmp_10 + (abs(tmp_11)))) ENDIF IN
                                                  	LET tmp_3 = IF (tmp_4 <= (-10317428604104855837448523736291688882839200227917824)) THEN ((((abs(tmp_5)) - tmp_6) * (5e-1)) + ((abs(q)) * ((abs(q)) / tmp_7))) ELSE tmp_8 ENDIF IN
                                                  	tmp_3
                                                  END code
                                                  \begin{array}{l}
                                                  \mathbf{if}\;\mathsf{min}\left(p, r\right) \leq -1.0317428604104856 \cdot 10^{+52}:\\
                                                  \;\;\;\;\mathsf{fma}\left(\left|\mathsf{max}\left(p, r\right)\right| - \mathsf{max}\left(p, r\right), 0.5, \left|q\right| \cdot \frac{\left|q\right|}{\mathsf{min}\left(p, r\right)}\right)\\
                                                  
                                                  \mathbf{elif}\;\mathsf{min}\left(p, r\right) \leq 3.799500869048362 \cdot 10^{-86}:\\
                                                  \;\;\;\;-\left|q\right|\\
                                                  
                                                  \mathbf{else}:\\
                                                  \;\;\;\;0.5 \cdot \left(\mathsf{min}\left(p, r\right) + \left|\mathsf{min}\left(p, r\right)\right|\right)\\
                                                  
                                                  
                                                  \end{array}
                                                  
                                                  Derivation
                                                  1. Split input into 3 regimes
                                                  2. if p < -1.0317428604104856e52

                                                    1. Initial program 24.7%

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

                                                        \[\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) + \frac{{q}^{2}}{p} \]
                                                      3. Step-by-step derivation
                                                        1. Applied rewrites20.3%

                                                          \[\leadsto \mathsf{fma}\left(0.5, \left|r\right| - r, \frac{{q}^{2}}{p}\right) \]
                                                        2. Applied rewrites20.3%

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

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

                                                          if -1.0317428604104856e52 < p < 3.7995008690483623e-86

                                                          1. Initial program 24.7%

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

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

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

                                                                \[\leadsto -q \]

                                                              if 3.7995008690483623e-86 < p

                                                              1. Initial program 24.7%

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

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

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

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

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

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

                                                                      \[\leadsto 0.5 \cdot \left(p + \left|p\right|\right) \]
                                                                  5. Recombined 3 regimes into one program.
                                                                  6. Add Preprocessing

                                                                  Alternative 5: 58.6% accurate, 1.0× speedup?

                                                                  \[\begin{array}{l} t_0 := {\left(\left|q\right|\right)}^{2}\\ \mathbf{if}\;t\_0 \leq 5 \cdot 10^{-271}:\\ \;\;\;\;0.5 \cdot \left(\mathsf{min}\left(p, r\right) + \left|\mathsf{min}\left(p, r\right)\right|\right)\\ \mathbf{elif}\;t\_0 \leq 10^{-31}:\\ \;\;\;\;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
                                                                    (let* ((t_0 (pow (fabs q) 2.0)))
                                                                    (if (<= t_0 5e-271)
                                                                      (* 0.5 (+ (fmin p r) (fabs (fmin p r))))
                                                                      (if (<= t_0 1e-31)
                                                                        (* 0.5 (- (fabs (fmax p r)) (fmax p r)))
                                                                        (- (fabs q))))))
                                                                  double code(double p, double r, double q) {
                                                                  	double t_0 = pow(fabs(q), 2.0);
                                                                  	double tmp;
                                                                  	if (t_0 <= 5e-271) {
                                                                  		tmp = 0.5 * (fmin(p, r) + fabs(fmin(p, r)));
                                                                  	} else if (t_0 <= 1e-31) {
                                                                  		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) :: t_0
                                                                      real(8) :: tmp
                                                                      t_0 = abs(q) ** 2.0d0
                                                                      if (t_0 <= 5d-271) then
                                                                          tmp = 0.5d0 * (fmin(p, r) + abs(fmin(p, r)))
                                                                      else if (t_0 <= 1d-31) 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 t_0 = Math.pow(Math.abs(q), 2.0);
                                                                  	double tmp;
                                                                  	if (t_0 <= 5e-271) {
                                                                  		tmp = 0.5 * (fmin(p, r) + Math.abs(fmin(p, r)));
                                                                  	} else if (t_0 <= 1e-31) {
                                                                  		tmp = 0.5 * (Math.abs(fmax(p, r)) - fmax(p, r));
                                                                  	} else {
                                                                  		tmp = -Math.abs(q);
                                                                  	}
                                                                  	return tmp;
                                                                  }
                                                                  
                                                                  def code(p, r, q):
                                                                  	t_0 = math.pow(math.fabs(q), 2.0)
                                                                  	tmp = 0
                                                                  	if t_0 <= 5e-271:
                                                                  		tmp = 0.5 * (fmin(p, r) + math.fabs(fmin(p, r)))
                                                                  	elif t_0 <= 1e-31:
                                                                  		tmp = 0.5 * (math.fabs(fmax(p, r)) - fmax(p, r))
                                                                  	else:
                                                                  		tmp = -math.fabs(q)
                                                                  	return tmp
                                                                  
                                                                  function code(p, r, q)
                                                                  	t_0 = abs(q) ^ 2.0
                                                                  	tmp = 0.0
                                                                  	if (t_0 <= 5e-271)
                                                                  		tmp = Float64(0.5 * Float64(fmin(p, r) + abs(fmin(p, r))));
                                                                  	elseif (t_0 <= 1e-31)
                                                                  		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)
                                                                  	t_0 = abs(q) ^ 2.0;
                                                                  	tmp = 0.0;
                                                                  	if (t_0 <= 5e-271)
                                                                  		tmp = 0.5 * (min(p, r) + abs(min(p, r)));
                                                                  	elseif (t_0 <= 1e-31)
                                                                  		tmp = 0.5 * (abs(max(p, r)) - max(p, r));
                                                                  	else
                                                                  		tmp = -abs(q);
                                                                  	end
                                                                  	tmp_2 = tmp;
                                                                  end
                                                                  
                                                                  code[p_, r_, q_] := Block[{t$95$0 = N[Power[N[Abs[q], $MachinePrecision], 2.0], $MachinePrecision]}, If[LessEqual[t$95$0, 5e-271], N[(0.5 * N[(N[Min[p, r], $MachinePrecision] + N[Abs[N[Min[p, r], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, 1e-31], 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 t_0 = ((abs(q)) ^ (2)) IN
                                                                  		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_8 = IF (p > r) THEN p ELSE r ENDIF IN
                                                                  		LET tmp_9 = IF (p > r) THEN p ELSE r ENDIF IN
                                                                  		LET tmp_7 = IF (t_0 <= (1000000000000000083336420607585985350931336026868654502364509783548862515410206308619223136702203191816806793212890625e-148)) THEN ((5e-1) * ((abs(tmp_8)) - tmp_9)) ELSE (- (abs(q))) ENDIF IN
                                                                  		LET tmp_2 = IF (t_0 <= (5000000000000000209150067989221637775103479960672679870247706115130295932880612872745298438551715853318067148272360300745488350924621144613936597911470875756987434956498260600565966666014538377630779950346371413982173062329619389392899990263448424026862084646485985069579928146808265249631585910288443334561598500877100740866128483376051886292135142641506344651304160686184986615946013042935398012380889951681844874318038329574699346506429785456133796463622782389177038299280973092920538773290151012712698552144039531631864665450552284967800287058541032928038777614323413547622455372745192611188580804362345993847519355991524283696890462204420746417099508107639849185943603515625e-949)) THEN ((5e-1) * (tmp_3 + (abs(tmp_4)))) ELSE tmp_7 ENDIF IN
                                                                  	tmp_2
                                                                  END code
                                                                  \begin{array}{l}
                                                                  t_0 := {\left(\left|q\right|\right)}^{2}\\
                                                                  \mathbf{if}\;t\_0 \leq 5 \cdot 10^{-271}:\\
                                                                  \;\;\;\;0.5 \cdot \left(\mathsf{min}\left(p, r\right) + \left|\mathsf{min}\left(p, r\right)\right|\right)\\
                                                                  
                                                                  \mathbf{elif}\;t\_0 \leq 10^{-31}:\\
                                                                  \;\;\;\;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 3 regimes
                                                                  2. if (pow.f64 q #s(literal 2 binary64)) < 5.0000000000000002e-271

                                                                    1. Initial program 24.7%

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

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

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

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

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

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

                                                                            \[\leadsto 0.5 \cdot \left(p + \left|p\right|\right) \]

                                                                          if 5.0000000000000002e-271 < (pow.f64 q #s(literal 2 binary64)) < 1.0000000000000001e-31

                                                                          1. Initial program 24.7%

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

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

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

                                                                              if 1.0000000000000001e-31 < (pow.f64 q #s(literal 2 binary64))

                                                                              1. Initial program 24.7%

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

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

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

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

                                                                                Alternative 6: 58.6% accurate, 1.7× speedup?

                                                                                \[\begin{array}{l} \mathbf{if}\;{\left(\left|q\right|\right)}^{2} \leq 10^{-31}:\\ \;\;\;\;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) 1e-31)
                                                                                  (* 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) <= 1e-31) {
                                                                                		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) <= 1d-31) 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) <= 1e-31) {
                                                                                		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) <= 1e-31:
                                                                                		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) <= 1e-31)
                                                                                		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) <= 1e-31)
                                                                                		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], 1e-31], 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)) <= (1000000000000000083336420607585985350931336026868654502364509783548862515410206308619223136702203191816806793212890625e-148)) 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 10^{-31}:\\
                                                                                \;\;\;\;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)) < 1.0000000000000001e-31

                                                                                  1. Initial program 24.7%

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

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

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

                                                                                      if 1.0000000000000001e-31 < (pow.f64 q #s(literal 2 binary64))

                                                                                      1. Initial program 24.7%

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

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

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

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

                                                                                        Alternative 7: 37.0% 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.7%

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

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

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

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

                                                                                            Reproduce

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