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

Percentage Accurate: 45.3% → 99.9%
Time: 2.8s
Alternatives: 7
Speedup: 2.1×

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: 45.3% 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: 99.9% accurate, 1.8× speedup?

\[\left(\mathsf{hypot}\left(2 \cdot \left(-\left|q\right|\right), p - r\right) + \left(\left|r\right| + \left|p\right|\right)\right) \cdot 0.5 \]
(FPCore (p r q)
  :precision binary64
  :pre TRUE
  (* (+ (hypot (* 2.0 (- (fabs q))) (- p r)) (+ (fabs r) (fabs p))) 0.5))
double code(double p, double r, double q) {
	return (hypot((2.0 * -fabs(q)), (p - r)) + (fabs(r) + fabs(p))) * 0.5;
}
public static double code(double p, double r, double q) {
	return (Math.hypot((2.0 * -Math.abs(q)), (p - r)) + (Math.abs(r) + Math.abs(p))) * 0.5;
}
def code(p, r, q):
	return (math.hypot((2.0 * -math.fabs(q)), (p - r)) + (math.fabs(r) + math.fabs(p))) * 0.5
function code(p, r, q)
	return Float64(Float64(hypot(Float64(2.0 * Float64(-abs(q))), Float64(p - r)) + Float64(abs(r) + abs(p))) * 0.5)
end
function tmp = code(p, r, q)
	tmp = (hypot((2.0 * -abs(q)), (p - r)) + (abs(r) + abs(p))) * 0.5;
end
code[p_, r_, q_] := N[(N[(N[Sqrt[N[(2.0 * (-N[Abs[q], $MachinePrecision])), $MachinePrecision] ^ 2 + N[(p - r), $MachinePrecision] ^ 2], $MachinePrecision] + N[(N[Abs[r], $MachinePrecision] + N[Abs[p], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * 0.5), $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 =
	((sqrt(((((2) * (- (abs(q)))) ^ (2)) + ((p - r) ^ (2))))) + ((abs(r)) + (abs(p)))) * (5e-1)
END code
\left(\mathsf{hypot}\left(2 \cdot \left(-\left|q\right|\right), p - r\right) + \left(\left|r\right| + \left|p\right|\right)\right) \cdot 0.5
Derivation
  1. Initial program 45.3%

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

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

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

        \[\leadsto \left(\mathsf{hypot}\left(2 \cdot \left(-q\right), -\left|r - p\right|\right) + \left(\left|r\right| + \left|p\right|\right)\right) \cdot 0.5 \]
      2. Applied rewrites99.9%

        \[\leadsto \left(\mathsf{hypot}\left(2 \cdot \left(-\left|q\right|\right), p - r\right) + \left(\left|r\right| + \left|p\right|\right)\right) \cdot 0.5 \]
      3. Add Preprocessing

      Alternative 2: 86.4% accurate, 1.3× speedup?

      \[\begin{array}{l} t_0 := \left|\mathsf{max}\left(p, r\right)\right|\\ t_1 := t\_0 + \left|\mathsf{min}\left(p, r\right)\right|\\ \mathbf{if}\;\mathsf{min}\left(p, r\right) \leq -8.376728107733935 \cdot 10^{+127}:\\ \;\;\;\;\left(\left(\mathsf{max}\left(p, r\right) - \mathsf{min}\left(p, r\right)\right) + t\_1\right) \cdot 0.5\\ \mathbf{else}:\\ \;\;\;\;\left(\mathsf{hypot}\left(\left|q\right| \cdot -2, t\_0\right) + t\_1\right) \cdot 0.5\\ \end{array} \]
      (FPCore (p r q)
        :precision binary64
        :pre TRUE
        (let* ((t_0 (fabs (fmax p r))) (t_1 (+ t_0 (fabs (fmin p r)))))
        (if (<= (fmin p r) -8.376728107733935e+127)
          (* (+ (- (fmax p r) (fmin p r)) t_1) 0.5)
          (* (+ (hypot (* (fabs q) -2.0) t_0) t_1) 0.5))))
      double code(double p, double r, double q) {
      	double t_0 = fabs(fmax(p, r));
      	double t_1 = t_0 + fabs(fmin(p, r));
      	double tmp;
      	if (fmin(p, r) <= -8.376728107733935e+127) {
      		tmp = ((fmax(p, r) - fmin(p, r)) + t_1) * 0.5;
      	} else {
      		tmp = (hypot((fabs(q) * -2.0), t_0) + t_1) * 0.5;
      	}
      	return tmp;
      }
      
      public static double code(double p, double r, double q) {
      	double t_0 = Math.abs(fmax(p, r));
      	double t_1 = t_0 + Math.abs(fmin(p, r));
      	double tmp;
      	if (fmin(p, r) <= -8.376728107733935e+127) {
      		tmp = ((fmax(p, r) - fmin(p, r)) + t_1) * 0.5;
      	} else {
      		tmp = (Math.hypot((Math.abs(q) * -2.0), t_0) + t_1) * 0.5;
      	}
      	return tmp;
      }
      
      def code(p, r, q):
      	t_0 = math.fabs(fmax(p, r))
      	t_1 = t_0 + math.fabs(fmin(p, r))
      	tmp = 0
      	if fmin(p, r) <= -8.376728107733935e+127:
      		tmp = ((fmax(p, r) - fmin(p, r)) + t_1) * 0.5
      	else:
      		tmp = (math.hypot((math.fabs(q) * -2.0), t_0) + t_1) * 0.5
      	return tmp
      
      function code(p, r, q)
      	t_0 = abs(fmax(p, r))
      	t_1 = Float64(t_0 + abs(fmin(p, r)))
      	tmp = 0.0
      	if (fmin(p, r) <= -8.376728107733935e+127)
      		tmp = Float64(Float64(Float64(fmax(p, r) - fmin(p, r)) + t_1) * 0.5);
      	else
      		tmp = Float64(Float64(hypot(Float64(abs(q) * -2.0), t_0) + t_1) * 0.5);
      	end
      	return tmp
      end
      
      function tmp_2 = code(p, r, q)
      	t_0 = abs(max(p, r));
      	t_1 = t_0 + abs(min(p, r));
      	tmp = 0.0;
      	if (min(p, r) <= -8.376728107733935e+127)
      		tmp = ((max(p, r) - min(p, r)) + t_1) * 0.5;
      	else
      		tmp = (hypot((abs(q) * -2.0), t_0) + t_1) * 0.5;
      	end
      	tmp_2 = tmp;
      end
      
      code[p_, r_, q_] := Block[{t$95$0 = N[Abs[N[Max[p, r], $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(t$95$0 + N[Abs[N[Min[p, r], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[Min[p, r], $MachinePrecision], -8.376728107733935e+127], N[(N[(N[(N[Max[p, r], $MachinePrecision] - N[Min[p, r], $MachinePrecision]), $MachinePrecision] + t$95$1), $MachinePrecision] * 0.5), $MachinePrecision], N[(N[(N[Sqrt[N[(N[Abs[q], $MachinePrecision] * -2.0), $MachinePrecision] ^ 2 + t$95$0 ^ 2], $MachinePrecision] + t$95$1), $MachinePrecision] * 0.5), $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 = (t_0 + (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_4 = IF (tmp_5 <= (-83767281077339354491025886286784871890094044195657503597511187552419412997948654100861293764526978671496850407539413408769114112)) THEN (((tmp_6 - tmp_7) + t_1) * (5e-1)) ELSE (((sqrt(((((abs(q)) * (-2)) ^ (2)) + (t_0 ^ (2))))) + t_1) * (5e-1)) ENDIF IN
      	tmp_4
      END code
      \begin{array}{l}
      t_0 := \left|\mathsf{max}\left(p, r\right)\right|\\
      t_1 := t\_0 + \left|\mathsf{min}\left(p, r\right)\right|\\
      \mathbf{if}\;\mathsf{min}\left(p, r\right) \leq -8.376728107733935 \cdot 10^{+127}:\\
      \;\;\;\;\left(\left(\mathsf{max}\left(p, r\right) - \mathsf{min}\left(p, r\right)\right) + t\_1\right) \cdot 0.5\\
      
      \mathbf{else}:\\
      \;\;\;\;\left(\mathsf{hypot}\left(\left|q\right| \cdot -2, t\_0\right) + t\_1\right) \cdot 0.5\\
      
      
      \end{array}
      
      Derivation
      1. Split input into 2 regimes
      2. if p < -8.3767281077339354e127

        1. Initial program 45.3%

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

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

            \[\leadsto \frac{1}{2} \cdot \left(\left(\left|p\right| + \left|r\right|\right) + r \cdot \left(1 + -1 \cdot \frac{p}{r}\right)\right) \]
          2. Applied rewrites34.9%

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

          if -8.3767281077339354e127 < p

          1. Initial program 45.3%

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

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

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

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

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

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

              Alternative 3: 81.0% accurate, 1.2× speedup?

              \[\begin{array}{l} t_0 := \left|\mathsf{max}\left(p, r\right)\right| + \left|\mathsf{min}\left(p, r\right)\right|\\ \mathbf{if}\;{\left(\left|q\right|\right)}^{2} \leq 4 \cdot 10^{+292}:\\ \;\;\;\;\left(\left(\mathsf{max}\left(p, r\right) - \mathsf{min}\left(p, r\right)\right) + t\_0\right) \cdot 0.5\\ \mathbf{else}:\\ \;\;\;\;\left(\left(\left|q\right| + \left|q\right|\right) + t\_0\right) \cdot 0.5\\ \end{array} \]
              (FPCore (p r q)
                :precision binary64
                :pre TRUE
                (let* ((t_0 (+ (fabs (fmax p r)) (fabs (fmin p r)))))
                (if (<= (pow (fabs q) 2.0) 4e+292)
                  (* (+ (- (fmax p r) (fmin p r)) t_0) 0.5)
                  (* (+ (+ (fabs q) (fabs q)) t_0) 0.5))))
              double code(double p, double r, double q) {
              	double t_0 = fabs(fmax(p, r)) + fabs(fmin(p, r));
              	double tmp;
              	if (pow(fabs(q), 2.0) <= 4e+292) {
              		tmp = ((fmax(p, r) - fmin(p, r)) + t_0) * 0.5;
              	} else {
              		tmp = ((fabs(q) + fabs(q)) + t_0) * 0.5;
              	}
              	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(fmax(p, r)) + abs(fmin(p, r))
                  if ((abs(q) ** 2.0d0) <= 4d+292) then
                      tmp = ((fmax(p, r) - fmin(p, r)) + t_0) * 0.5d0
                  else
                      tmp = ((abs(q) + abs(q)) + t_0) * 0.5d0
                  end if
                  code = tmp
              end function
              
              public static double code(double p, double r, double q) {
              	double t_0 = Math.abs(fmax(p, r)) + Math.abs(fmin(p, r));
              	double tmp;
              	if (Math.pow(Math.abs(q), 2.0) <= 4e+292) {
              		tmp = ((fmax(p, r) - fmin(p, r)) + t_0) * 0.5;
              	} else {
              		tmp = ((Math.abs(q) + Math.abs(q)) + t_0) * 0.5;
              	}
              	return tmp;
              }
              
              def code(p, r, q):
              	t_0 = math.fabs(fmax(p, r)) + math.fabs(fmin(p, r))
              	tmp = 0
              	if math.pow(math.fabs(q), 2.0) <= 4e+292:
              		tmp = ((fmax(p, r) - fmin(p, r)) + t_0) * 0.5
              	else:
              		tmp = ((math.fabs(q) + math.fabs(q)) + t_0) * 0.5
              	return tmp
              
              function code(p, r, q)
              	t_0 = Float64(abs(fmax(p, r)) + abs(fmin(p, r)))
              	tmp = 0.0
              	if ((abs(q) ^ 2.0) <= 4e+292)
              		tmp = Float64(Float64(Float64(fmax(p, r) - fmin(p, r)) + t_0) * 0.5);
              	else
              		tmp = Float64(Float64(Float64(abs(q) + abs(q)) + t_0) * 0.5);
              	end
              	return tmp
              end
              
              function tmp_2 = code(p, r, q)
              	t_0 = abs(max(p, r)) + abs(min(p, r));
              	tmp = 0.0;
              	if ((abs(q) ^ 2.0) <= 4e+292)
              		tmp = ((max(p, r) - min(p, r)) + t_0) * 0.5;
              	else
              		tmp = ((abs(q) + abs(q)) + t_0) * 0.5;
              	end
              	tmp_2 = tmp;
              end
              
              code[p_, r_, q_] := Block[{t$95$0 = N[(N[Abs[N[Max[p, r], $MachinePrecision]], $MachinePrecision] + N[Abs[N[Min[p, r], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[Power[N[Abs[q], $MachinePrecision], 2.0], $MachinePrecision], 4e+292], N[(N[(N[(N[Max[p, r], $MachinePrecision] - N[Min[p, r], $MachinePrecision]), $MachinePrecision] + t$95$0), $MachinePrecision] * 0.5), $MachinePrecision], N[(N[(N[(N[Abs[q], $MachinePrecision] + N[Abs[q], $MachinePrecision]), $MachinePrecision] + t$95$0), $MachinePrecision] * 0.5), $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 = ((abs(tmp)) + (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_4 = IF (((abs(q)) ^ (2)) <= (40000000000000000530263959134296650722746244358345840142528125911769970907617012858463917672157449998909498554263568363952491898600028103138206953210986926743629581261021098587444232750232858470317984807330649410342155342294546390088430246843766074240114997507336380714205155856460222902042624)) THEN (((tmp_5 - tmp_6) + t_0) * (5e-1)) ELSE ((((abs(q)) + (abs(q))) + t_0) * (5e-1)) ENDIF IN
              	tmp_4
              END code
              \begin{array}{l}
              t_0 := \left|\mathsf{max}\left(p, r\right)\right| + \left|\mathsf{min}\left(p, r\right)\right|\\
              \mathbf{if}\;{\left(\left|q\right|\right)}^{2} \leq 4 \cdot 10^{+292}:\\
              \;\;\;\;\left(\left(\mathsf{max}\left(p, r\right) - \mathsf{min}\left(p, r\right)\right) + t\_0\right) \cdot 0.5\\
              
              \mathbf{else}:\\
              \;\;\;\;\left(\left(\left|q\right| + \left|q\right|\right) + t\_0\right) \cdot 0.5\\
              
              
              \end{array}
              
              Derivation
              1. Split input into 2 regimes
              2. if (pow.f64 q #s(literal 2 binary64)) < 4.0000000000000001e292

                1. Initial program 45.3%

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

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

                    \[\leadsto \frac{1}{2} \cdot \left(\left(\left|p\right| + \left|r\right|\right) + r \cdot \left(1 + -1 \cdot \frac{p}{r}\right)\right) \]
                  2. Applied rewrites34.9%

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

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

                  1. Initial program 45.3%

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

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

                      \[\leadsto \frac{1}{2} \cdot \left(\left(\left|p\right| + \left|r\right|\right) + 2 \cdot q\right) \]
                    2. Applied rewrites29.3%

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

                  Alternative 4: 65.0% accurate, 1.7× speedup?

                  \[\begin{array}{l} t_0 := \left|\mathsf{max}\left(p, r\right)\right| + \left|\mathsf{min}\left(p, r\right)\right|\\ \mathbf{if}\;\mathsf{min}\left(p, r\right) \leq -8.376728107733935 \cdot 10^{+127}:\\ \;\;\;\;\left(\left(-\mathsf{min}\left(p, r\right)\right) + t\_0\right) \cdot 0.5\\ \mathbf{elif}\;\mathsf{min}\left(p, r\right) \leq 4.1502214538165787 \cdot 10^{-268}:\\ \;\;\;\;\left(\left(\left|q\right| + \left|q\right|\right) + t\_0\right) \cdot 0.5\\ \mathbf{else}:\\ \;\;\;\;\left(\mathsf{max}\left(p, r\right) + t\_0\right) \cdot 0.5\\ \end{array} \]
                  (FPCore (p r q)
                    :precision binary64
                    :pre TRUE
                    (let* ((t_0 (+ (fabs (fmax p r)) (fabs (fmin p r)))))
                    (if (<= (fmin p r) -8.376728107733935e+127)
                      (* (+ (- (fmin p r)) t_0) 0.5)
                      (if (<= (fmin p r) 4.1502214538165787e-268)
                        (* (+ (+ (fabs q) (fabs q)) t_0) 0.5)
                        (* (+ (fmax p r) t_0) 0.5)))))
                  double code(double p, double r, double q) {
                  	double t_0 = fabs(fmax(p, r)) + fabs(fmin(p, r));
                  	double tmp;
                  	if (fmin(p, r) <= -8.376728107733935e+127) {
                  		tmp = (-fmin(p, r) + t_0) * 0.5;
                  	} else if (fmin(p, r) <= 4.1502214538165787e-268) {
                  		tmp = ((fabs(q) + fabs(q)) + t_0) * 0.5;
                  	} else {
                  		tmp = (fmax(p, r) + t_0) * 0.5;
                  	}
                  	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(fmax(p, r)) + abs(fmin(p, r))
                      if (fmin(p, r) <= (-8.376728107733935d+127)) then
                          tmp = (-fmin(p, r) + t_0) * 0.5d0
                      else if (fmin(p, r) <= 4.1502214538165787d-268) then
                          tmp = ((abs(q) + abs(q)) + t_0) * 0.5d0
                      else
                          tmp = (fmax(p, r) + t_0) * 0.5d0
                      end if
                      code = tmp
                  end function
                  
                  public static double code(double p, double r, double q) {
                  	double t_0 = Math.abs(fmax(p, r)) + Math.abs(fmin(p, r));
                  	double tmp;
                  	if (fmin(p, r) <= -8.376728107733935e+127) {
                  		tmp = (-fmin(p, r) + t_0) * 0.5;
                  	} else if (fmin(p, r) <= 4.1502214538165787e-268) {
                  		tmp = ((Math.abs(q) + Math.abs(q)) + t_0) * 0.5;
                  	} else {
                  		tmp = (fmax(p, r) + t_0) * 0.5;
                  	}
                  	return tmp;
                  }
                  
                  def code(p, r, q):
                  	t_0 = math.fabs(fmax(p, r)) + math.fabs(fmin(p, r))
                  	tmp = 0
                  	if fmin(p, r) <= -8.376728107733935e+127:
                  		tmp = (-fmin(p, r) + t_0) * 0.5
                  	elif fmin(p, r) <= 4.1502214538165787e-268:
                  		tmp = ((math.fabs(q) + math.fabs(q)) + t_0) * 0.5
                  	else:
                  		tmp = (fmax(p, r) + t_0) * 0.5
                  	return tmp
                  
                  function code(p, r, q)
                  	t_0 = Float64(abs(fmax(p, r)) + abs(fmin(p, r)))
                  	tmp = 0.0
                  	if (fmin(p, r) <= -8.376728107733935e+127)
                  		tmp = Float64(Float64(Float64(-fmin(p, r)) + t_0) * 0.5);
                  	elseif (fmin(p, r) <= 4.1502214538165787e-268)
                  		tmp = Float64(Float64(Float64(abs(q) + abs(q)) + t_0) * 0.5);
                  	else
                  		tmp = Float64(Float64(fmax(p, r) + t_0) * 0.5);
                  	end
                  	return tmp
                  end
                  
                  function tmp_2 = code(p, r, q)
                  	t_0 = abs(max(p, r)) + abs(min(p, r));
                  	tmp = 0.0;
                  	if (min(p, r) <= -8.376728107733935e+127)
                  		tmp = (-min(p, r) + t_0) * 0.5;
                  	elseif (min(p, r) <= 4.1502214538165787e-268)
                  		tmp = ((abs(q) + abs(q)) + t_0) * 0.5;
                  	else
                  		tmp = (max(p, r) + t_0) * 0.5;
                  	end
                  	tmp_2 = tmp;
                  end
                  
                  code[p_, r_, q_] := Block[{t$95$0 = N[(N[Abs[N[Max[p, r], $MachinePrecision]], $MachinePrecision] + N[Abs[N[Min[p, r], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[Min[p, r], $MachinePrecision], -8.376728107733935e+127], N[(N[((-N[Min[p, r], $MachinePrecision]) + t$95$0), $MachinePrecision] * 0.5), $MachinePrecision], If[LessEqual[N[Min[p, r], $MachinePrecision], 4.1502214538165787e-268], N[(N[(N[(N[Abs[q], $MachinePrecision] + N[Abs[q], $MachinePrecision]), $MachinePrecision] + t$95$0), $MachinePrecision] * 0.5), $MachinePrecision], N[(N[(N[Max[p, r], $MachinePrecision] + t$95$0), $MachinePrecision] * 0.5), $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 = ((abs(tmp)) + (abs(tmp_1))) IN
                  		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_7 = IF (p < r) THEN p ELSE r ENDIF IN
                  		LET tmp_8 = IF (p > r) THEN p ELSE r ENDIF IN
                  		LET tmp_6 = IF (tmp_7 <= (41502214538165787167399762565737904314641852875584512934619563441628236269392711209069497725876522392918936106621222665101543313761145763375337361377352967157103549808646328382580701886622436468432548973331870398463488710057472304324979359119485936098186594444782253136104919372273610239610449722668573291427248060136895881496460104546903295162702189744678393672712474837089395825233593889715027246506687212045946051590827883816962167346982480851957653216197994898541075947339204897434626454599892720524625165956196184120547474240446388128978785103512622868300637530611386596291306218173439856400995854106302430521081608784188764216249722949214628897607326507568359375e-935)) THEN ((((abs(q)) + (abs(q))) + t_0) * (5e-1)) ELSE ((tmp_8 + t_0) * (5e-1)) ENDIF IN
                  		LET tmp_3 = IF (tmp_4 <= (-83767281077339354491025886286784871890094044195657503597511187552419412997948654100861293764526978671496850407539413408769114112)) THEN (((- tmp_5) + t_0) * (5e-1)) ELSE tmp_6 ENDIF IN
                  	tmp_3
                  END code
                  \begin{array}{l}
                  t_0 := \left|\mathsf{max}\left(p, r\right)\right| + \left|\mathsf{min}\left(p, r\right)\right|\\
                  \mathbf{if}\;\mathsf{min}\left(p, r\right) \leq -8.376728107733935 \cdot 10^{+127}:\\
                  \;\;\;\;\left(\left(-\mathsf{min}\left(p, r\right)\right) + t\_0\right) \cdot 0.5\\
                  
                  \mathbf{elif}\;\mathsf{min}\left(p, r\right) \leq 4.1502214538165787 \cdot 10^{-268}:\\
                  \;\;\;\;\left(\left(\left|q\right| + \left|q\right|\right) + t\_0\right) \cdot 0.5\\
                  
                  \mathbf{else}:\\
                  \;\;\;\;\left(\mathsf{max}\left(p, r\right) + t\_0\right) \cdot 0.5\\
                  
                  
                  \end{array}
                  
                  Derivation
                  1. Split input into 3 regimes
                  2. if p < -8.3767281077339354e127

                    1. Initial program 45.3%

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

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

                        \[\leadsto \frac{1}{2} \cdot \left(\left(\left|p\right| + \left|r\right|\right) + -1 \cdot p\right) \]
                      2. Applied rewrites24.4%

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

                      if -8.3767281077339354e127 < p < 4.1502214538165787e-268

                      1. Initial program 45.3%

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

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

                          \[\leadsto \frac{1}{2} \cdot \left(\left(\left|p\right| + \left|r\right|\right) + 2 \cdot q\right) \]
                        2. Applied rewrites29.3%

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

                        if 4.1502214538165787e-268 < p

                        1. Initial program 45.3%

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

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

                            \[\leadsto \frac{1}{2} \cdot \left(\left(\left|p\right| + \left|r\right|\right) + r \cdot \left(1 + -1 \cdot \frac{p}{r}\right)\right) \]
                          2. Applied rewrites34.9%

                            \[\leadsto \left(\left(r - p\right) + \left(\left|r\right| + \left|p\right|\right)\right) \cdot 0.5 \]
                          3. Taylor expanded in p around 0

                            \[\leadsto \left(r + \left(\left|r\right| + \left|p\right|\right)\right) \cdot 0.5 \]
                          4. Step-by-step derivation
                            1. Applied rewrites24.4%

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

                          Alternative 5: 59.2% accurate, 2.1× speedup?

                          \[\begin{array}{l} t_0 := \left|\mathsf{max}\left(p, r\right)\right| + \left|\mathsf{min}\left(p, r\right)\right|\\ \mathbf{if}\;\mathsf{max}\left(p, r\right) \leq 1.7222372352353597 \cdot 10^{-34}:\\ \;\;\;\;\left(\left(-\mathsf{min}\left(p, r\right)\right) + t\_0\right) \cdot 0.5\\ \mathbf{else}:\\ \;\;\;\;\left(\mathsf{max}\left(p, r\right) + t\_0\right) \cdot 0.5\\ \end{array} \]
                          (FPCore (p r q)
                            :precision binary64
                            :pre TRUE
                            (let* ((t_0 (+ (fabs (fmax p r)) (fabs (fmin p r)))))
                            (if (<= (fmax p r) 1.7222372352353597e-34)
                              (* (+ (- (fmin p r)) t_0) 0.5)
                              (* (+ (fmax p r) t_0) 0.5))))
                          double code(double p, double r, double q) {
                          	double t_0 = fabs(fmax(p, r)) + fabs(fmin(p, r));
                          	double tmp;
                          	if (fmax(p, r) <= 1.7222372352353597e-34) {
                          		tmp = (-fmin(p, r) + t_0) * 0.5;
                          	} else {
                          		tmp = (fmax(p, r) + t_0) * 0.5;
                          	}
                          	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(fmax(p, r)) + abs(fmin(p, r))
                              if (fmax(p, r) <= 1.7222372352353597d-34) then
                                  tmp = (-fmin(p, r) + t_0) * 0.5d0
                              else
                                  tmp = (fmax(p, r) + t_0) * 0.5d0
                              end if
                              code = tmp
                          end function
                          
                          public static double code(double p, double r, double q) {
                          	double t_0 = Math.abs(fmax(p, r)) + Math.abs(fmin(p, r));
                          	double tmp;
                          	if (fmax(p, r) <= 1.7222372352353597e-34) {
                          		tmp = (-fmin(p, r) + t_0) * 0.5;
                          	} else {
                          		tmp = (fmax(p, r) + t_0) * 0.5;
                          	}
                          	return tmp;
                          }
                          
                          def code(p, r, q):
                          	t_0 = math.fabs(fmax(p, r)) + math.fabs(fmin(p, r))
                          	tmp = 0
                          	if fmax(p, r) <= 1.7222372352353597e-34:
                          		tmp = (-fmin(p, r) + t_0) * 0.5
                          	else:
                          		tmp = (fmax(p, r) + t_0) * 0.5
                          	return tmp
                          
                          function code(p, r, q)
                          	t_0 = Float64(abs(fmax(p, r)) + abs(fmin(p, r)))
                          	tmp = 0.0
                          	if (fmax(p, r) <= 1.7222372352353597e-34)
                          		tmp = Float64(Float64(Float64(-fmin(p, r)) + t_0) * 0.5);
                          	else
                          		tmp = Float64(Float64(fmax(p, r) + t_0) * 0.5);
                          	end
                          	return tmp
                          end
                          
                          function tmp_2 = code(p, r, q)
                          	t_0 = abs(max(p, r)) + abs(min(p, r));
                          	tmp = 0.0;
                          	if (max(p, r) <= 1.7222372352353597e-34)
                          		tmp = (-min(p, r) + t_0) * 0.5;
                          	else
                          		tmp = (max(p, r) + t_0) * 0.5;
                          	end
                          	tmp_2 = tmp;
                          end
                          
                          code[p_, r_, q_] := Block[{t$95$0 = N[(N[Abs[N[Max[p, r], $MachinePrecision]], $MachinePrecision] + N[Abs[N[Min[p, r], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[Max[p, r], $MachinePrecision], 1.7222372352353597e-34], N[(N[((-N[Min[p, r], $MachinePrecision]) + t$95$0), $MachinePrecision] * 0.5), $MachinePrecision], N[(N[(N[Max[p, r], $MachinePrecision] + t$95$0), $MachinePrecision] * 0.5), $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 = ((abs(tmp)) + (abs(tmp_1))) IN
                          		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_3 = IF (tmp_4 <= (17222372352353597110761042901716655139685650863443352998444834040884961597758724599207071949413805356243756250478327274322509765625e-164)) THEN (((- tmp_5) + t_0) * (5e-1)) ELSE ((tmp_6 + t_0) * (5e-1)) ENDIF IN
                          	tmp_3
                          END code
                          \begin{array}{l}
                          t_0 := \left|\mathsf{max}\left(p, r\right)\right| + \left|\mathsf{min}\left(p, r\right)\right|\\
                          \mathbf{if}\;\mathsf{max}\left(p, r\right) \leq 1.7222372352353597 \cdot 10^{-34}:\\
                          \;\;\;\;\left(\left(-\mathsf{min}\left(p, r\right)\right) + t\_0\right) \cdot 0.5\\
                          
                          \mathbf{else}:\\
                          \;\;\;\;\left(\mathsf{max}\left(p, r\right) + t\_0\right) \cdot 0.5\\
                          
                          
                          \end{array}
                          
                          Derivation
                          1. Split input into 2 regimes
                          2. if r < 1.7222372352353597e-34

                            1. Initial program 45.3%

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

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

                                \[\leadsto \frac{1}{2} \cdot \left(\left(\left|p\right| + \left|r\right|\right) + -1 \cdot p\right) \]
                              2. Applied rewrites24.4%

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

                              if 1.7222372352353597e-34 < r

                              1. Initial program 45.3%

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

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

                                  \[\leadsto \frac{1}{2} \cdot \left(\left(\left|p\right| + \left|r\right|\right) + r \cdot \left(1 + -1 \cdot \frac{p}{r}\right)\right) \]
                                2. Applied rewrites34.9%

                                  \[\leadsto \left(\left(r - p\right) + \left(\left|r\right| + \left|p\right|\right)\right) \cdot 0.5 \]
                                3. Taylor expanded in p around 0

                                  \[\leadsto \left(r + \left(\left|r\right| + \left|p\right|\right)\right) \cdot 0.5 \]
                                4. Step-by-step derivation
                                  1. Applied rewrites24.4%

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

                                Alternative 6: 40.2% accurate, 2.9× speedup?

                                \[\left(\mathsf{max}\left(p, r\right) + \left(\left|\mathsf{max}\left(p, r\right)\right| + \left|\mathsf{min}\left(p, r\right)\right|\right)\right) \cdot 0.5 \]
                                (FPCore (p r q)
                                  :precision binary64
                                  :pre TRUE
                                  (* (+ (fmax p r) (+ (fabs (fmax p r)) (fabs (fmin p r)))) 0.5))
                                double code(double p, double r, double q) {
                                	return (fmax(p, r) + (fabs(fmax(p, r)) + fabs(fmin(p, r)))) * 0.5;
                                }
                                
                                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 = (fmax(p, r) + (abs(fmax(p, r)) + abs(fmin(p, r)))) * 0.5d0
                                end function
                                
                                public static double code(double p, double r, double q) {
                                	return (fmax(p, r) + (Math.abs(fmax(p, r)) + Math.abs(fmin(p, r)))) * 0.5;
                                }
                                
                                def code(p, r, q):
                                	return (fmax(p, r) + (math.fabs(fmax(p, r)) + math.fabs(fmin(p, r)))) * 0.5
                                
                                function code(p, r, q)
                                	return Float64(Float64(fmax(p, r) + Float64(abs(fmax(p, r)) + abs(fmin(p, r)))) * 0.5)
                                end
                                
                                function tmp = code(p, r, q)
                                	tmp = (max(p, r) + (abs(max(p, r)) + abs(min(p, r)))) * 0.5;
                                end
                                
                                code[p_, r_, q_] := N[(N[(N[Max[p, r], $MachinePrecision] + N[(N[Abs[N[Max[p, r], $MachinePrecision]], $MachinePrecision] + N[Abs[N[Min[p, r], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * 0.5), $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 tmp_2 = IF (p < r) THEN p ELSE r ENDIF IN
                                	(tmp + ((abs(tmp_1)) + (abs(tmp_2)))) * (5e-1)
                                END code
                                \left(\mathsf{max}\left(p, r\right) + \left(\left|\mathsf{max}\left(p, r\right)\right| + \left|\mathsf{min}\left(p, r\right)\right|\right)\right) \cdot 0.5
                                
                                Derivation
                                1. Initial program 45.3%

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

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

                                    \[\leadsto \frac{1}{2} \cdot \left(\left(\left|p\right| + \left|r\right|\right) + r \cdot \left(1 + -1 \cdot \frac{p}{r}\right)\right) \]
                                  2. Applied rewrites34.9%

                                    \[\leadsto \left(\left(r - p\right) + \left(\left|r\right| + \left|p\right|\right)\right) \cdot 0.5 \]
                                  3. Taylor expanded in p around 0

                                    \[\leadsto \left(r + \left(\left|r\right| + \left|p\right|\right)\right) \cdot 0.5 \]
                                  4. Step-by-step derivation
                                    1. Applied rewrites24.4%

                                      \[\leadsto \left(r + \left(\left|r\right| + \left|p\right|\right)\right) \cdot 0.5 \]
                                    2. Add Preprocessing

                                    Alternative 7: 18.8% accurate, 14.8× speedup?

                                    \[-1 \cdot q \]
                                    (FPCore (p r q)
                                      :precision binary64
                                      :pre TRUE
                                      (* -1.0 q))
                                    double code(double p, double r, double q) {
                                    	return -1.0 * 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 = (-1.0d0) * q
                                    end function
                                    
                                    public static double code(double p, double r, double q) {
                                    	return -1.0 * q;
                                    }
                                    
                                    def code(p, r, q):
                                    	return -1.0 * q
                                    
                                    function code(p, r, q)
                                    	return Float64(-1.0 * q)
                                    end
                                    
                                    function tmp = code(p, r, q)
                                    	tmp = -1.0 * q;
                                    end
                                    
                                    code[p_, r_, q_] := N[(-1.0 * 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 =
                                    	(-1) * q
                                    END code
                                    -1 \cdot q
                                    
                                    Derivation
                                    1. Initial program 45.3%

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

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

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

                                      Reproduce

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