quad2p (problem 3.2.1, positive)

Percentage Accurate: 52.1% → 85.2%
Time: 8.2s
Alternatives: 5
Speedup: 15.9×

Specification

?
\[\begin{array}{l} \\ \frac{\left(-b_2\right) + \sqrt{b_2 \cdot b_2 - a \cdot c}}{a} \end{array} \]
(FPCore (a b_2 c)
 :precision binary64
 (/ (+ (- b_2) (sqrt (- (* b_2 b_2) (* a c)))) a))
double code(double a, double b_2, double c) {
	return (-b_2 + sqrt(((b_2 * b_2) - (a * c)))) / a;
}
real(8) function code(a, b_2, c)
    real(8), intent (in) :: a
    real(8), intent (in) :: b_2
    real(8), intent (in) :: c
    code = (-b_2 + sqrt(((b_2 * b_2) - (a * c)))) / a
end function
public static double code(double a, double b_2, double c) {
	return (-b_2 + Math.sqrt(((b_2 * b_2) - (a * c)))) / a;
}
def code(a, b_2, c):
	return (-b_2 + math.sqrt(((b_2 * b_2) - (a * c)))) / a
function code(a, b_2, c)
	return Float64(Float64(Float64(-b_2) + sqrt(Float64(Float64(b_2 * b_2) - Float64(a * c)))) / a)
end
function tmp = code(a, b_2, c)
	tmp = (-b_2 + sqrt(((b_2 * b_2) - (a * c)))) / a;
end
code[a_, b$95$2_, c_] := N[(N[((-b$95$2) + N[Sqrt[N[(N[(b$95$2 * b$95$2), $MachinePrecision] - N[(a * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision]
\begin{array}{l}

\\
\frac{\left(-b_2\right) + \sqrt{b_2 \cdot b_2 - a \cdot c}}{a}
\end{array}

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

Herbie found 5 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: 52.1% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \frac{\left(-b_2\right) + \sqrt{b_2 \cdot b_2 - a \cdot c}}{a} \end{array} \]
(FPCore (a b_2 c)
 :precision binary64
 (/ (+ (- b_2) (sqrt (- (* b_2 b_2) (* a c)))) a))
double code(double a, double b_2, double c) {
	return (-b_2 + sqrt(((b_2 * b_2) - (a * c)))) / a;
}
real(8) function code(a, b_2, c)
    real(8), intent (in) :: a
    real(8), intent (in) :: b_2
    real(8), intent (in) :: c
    code = (-b_2 + sqrt(((b_2 * b_2) - (a * c)))) / a
end function
public static double code(double a, double b_2, double c) {
	return (-b_2 + Math.sqrt(((b_2 * b_2) - (a * c)))) / a;
}
def code(a, b_2, c):
	return (-b_2 + math.sqrt(((b_2 * b_2) - (a * c)))) / a
function code(a, b_2, c)
	return Float64(Float64(Float64(-b_2) + sqrt(Float64(Float64(b_2 * b_2) - Float64(a * c)))) / a)
end
function tmp = code(a, b_2, c)
	tmp = (-b_2 + sqrt(((b_2 * b_2) - (a * c)))) / a;
end
code[a_, b$95$2_, c_] := N[(N[((-b$95$2) + N[Sqrt[N[(N[(b$95$2 * b$95$2), $MachinePrecision] - N[(a * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision]
\begin{array}{l}

\\
\frac{\left(-b_2\right) + \sqrt{b_2 \cdot b_2 - a \cdot c}}{a}
\end{array}

Alternative 1: 85.2% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;b_2 \leq -1 \cdot 10^{+154}:\\ \;\;\;\;-2 \cdot \frac{b_2}{a} + 0.5 \cdot \frac{c}{b_2}\\ \mathbf{elif}\;b_2 \leq 1.6 \cdot 10^{-138}:\\ \;\;\;\;\frac{\sqrt{b_2 \cdot b_2 - a \cdot c} - b_2}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b_2} \cdot -0.5\\ \end{array} \end{array} \]
(FPCore (a b_2 c)
 :precision binary64
 (if (<= b_2 -1e+154)
   (+ (* -2.0 (/ b_2 a)) (* 0.5 (/ c b_2)))
   (if (<= b_2 1.6e-138)
     (/ (- (sqrt (- (* b_2 b_2) (* a c))) b_2) a)
     (* (/ c b_2) -0.5))))
double code(double a, double b_2, double c) {
	double tmp;
	if (b_2 <= -1e+154) {
		tmp = (-2.0 * (b_2 / a)) + (0.5 * (c / b_2));
	} else if (b_2 <= 1.6e-138) {
		tmp = (sqrt(((b_2 * b_2) - (a * c))) - b_2) / a;
	} else {
		tmp = (c / b_2) * -0.5;
	}
	return tmp;
}
real(8) function code(a, b_2, c)
    real(8), intent (in) :: a
    real(8), intent (in) :: b_2
    real(8), intent (in) :: c
    real(8) :: tmp
    if (b_2 <= (-1d+154)) then
        tmp = ((-2.0d0) * (b_2 / a)) + (0.5d0 * (c / b_2))
    else if (b_2 <= 1.6d-138) then
        tmp = (sqrt(((b_2 * b_2) - (a * c))) - b_2) / a
    else
        tmp = (c / b_2) * (-0.5d0)
    end if
    code = tmp
end function
public static double code(double a, double b_2, double c) {
	double tmp;
	if (b_2 <= -1e+154) {
		tmp = (-2.0 * (b_2 / a)) + (0.5 * (c / b_2));
	} else if (b_2 <= 1.6e-138) {
		tmp = (Math.sqrt(((b_2 * b_2) - (a * c))) - b_2) / a;
	} else {
		tmp = (c / b_2) * -0.5;
	}
	return tmp;
}
def code(a, b_2, c):
	tmp = 0
	if b_2 <= -1e+154:
		tmp = (-2.0 * (b_2 / a)) + (0.5 * (c / b_2))
	elif b_2 <= 1.6e-138:
		tmp = (math.sqrt(((b_2 * b_2) - (a * c))) - b_2) / a
	else:
		tmp = (c / b_2) * -0.5
	return tmp
function code(a, b_2, c)
	tmp = 0.0
	if (b_2 <= -1e+154)
		tmp = Float64(Float64(-2.0 * Float64(b_2 / a)) + Float64(0.5 * Float64(c / b_2)));
	elseif (b_2 <= 1.6e-138)
		tmp = Float64(Float64(sqrt(Float64(Float64(b_2 * b_2) - Float64(a * c))) - b_2) / a);
	else
		tmp = Float64(Float64(c / b_2) * -0.5);
	end
	return tmp
end
function tmp_2 = code(a, b_2, c)
	tmp = 0.0;
	if (b_2 <= -1e+154)
		tmp = (-2.0 * (b_2 / a)) + (0.5 * (c / b_2));
	elseif (b_2 <= 1.6e-138)
		tmp = (sqrt(((b_2 * b_2) - (a * c))) - b_2) / a;
	else
		tmp = (c / b_2) * -0.5;
	end
	tmp_2 = tmp;
end
code[a_, b$95$2_, c_] := If[LessEqual[b$95$2, -1e+154], N[(N[(-2.0 * N[(b$95$2 / a), $MachinePrecision]), $MachinePrecision] + N[(0.5 * N[(c / b$95$2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[b$95$2, 1.6e-138], N[(N[(N[Sqrt[N[(N[(b$95$2 * b$95$2), $MachinePrecision] - N[(a * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b$95$2), $MachinePrecision] / a), $MachinePrecision], N[(N[(c / b$95$2), $MachinePrecision] * -0.5), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;b_2 \leq -1 \cdot 10^{+154}:\\
\;\;\;\;-2 \cdot \frac{b_2}{a} + 0.5 \cdot \frac{c}{b_2}\\

\mathbf{elif}\;b_2 \leq 1.6 \cdot 10^{-138}:\\
\;\;\;\;\frac{\sqrt{b_2 \cdot b_2 - a \cdot c} - b_2}{a}\\

\mathbf{else}:\\
\;\;\;\;\frac{c}{b_2} \cdot -0.5\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if b_2 < -1.00000000000000004e154

    1. Initial program 45.5%

      \[\frac{\left(-b_2\right) + \sqrt{b_2 \cdot b_2 - a \cdot c}}{a} \]
    2. Step-by-step derivation
      1. +-commutative45.5%

        \[\leadsto \frac{\color{blue}{\sqrt{b_2 \cdot b_2 - a \cdot c} + \left(-b_2\right)}}{a} \]
      2. unsub-neg45.5%

        \[\leadsto \frac{\color{blue}{\sqrt{b_2 \cdot b_2 - a \cdot c} - b_2}}{a} \]
    3. Simplified45.5%

      \[\leadsto \color{blue}{\frac{\sqrt{b_2 \cdot b_2 - a \cdot c} - b_2}{a}} \]
    4. Taylor expanded in b_2 around -inf 100.0%

      \[\leadsto \color{blue}{-2 \cdot \frac{b_2}{a} + 0.5 \cdot \frac{c}{b_2}} \]

    if -1.00000000000000004e154 < b_2 < 1.60000000000000005e-138

    1. Initial program 85.2%

      \[\frac{\left(-b_2\right) + \sqrt{b_2 \cdot b_2 - a \cdot c}}{a} \]
    2. Step-by-step derivation
      1. +-commutative85.2%

        \[\leadsto \frac{\color{blue}{\sqrt{b_2 \cdot b_2 - a \cdot c} + \left(-b_2\right)}}{a} \]
      2. unsub-neg85.2%

        \[\leadsto \frac{\color{blue}{\sqrt{b_2 \cdot b_2 - a \cdot c} - b_2}}{a} \]
    3. Simplified85.2%

      \[\leadsto \color{blue}{\frac{\sqrt{b_2 \cdot b_2 - a \cdot c} - b_2}{a}} \]

    if 1.60000000000000005e-138 < b_2

    1. Initial program 18.7%

      \[\frac{\left(-b_2\right) + \sqrt{b_2 \cdot b_2 - a \cdot c}}{a} \]
    2. Step-by-step derivation
      1. +-commutative18.7%

        \[\leadsto \frac{\color{blue}{\sqrt{b_2 \cdot b_2 - a \cdot c} + \left(-b_2\right)}}{a} \]
      2. unsub-neg18.7%

        \[\leadsto \frac{\color{blue}{\sqrt{b_2 \cdot b_2 - a \cdot c} - b_2}}{a} \]
    3. Simplified18.7%

      \[\leadsto \color{blue}{\frac{\sqrt{b_2 \cdot b_2 - a \cdot c} - b_2}{a}} \]
    4. Taylor expanded in b_2 around inf 85.8%

      \[\leadsto \color{blue}{-0.5 \cdot \frac{c}{b_2}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification88.2%

    \[\leadsto \begin{array}{l} \mathbf{if}\;b_2 \leq -1 \cdot 10^{+154}:\\ \;\;\;\;-2 \cdot \frac{b_2}{a} + 0.5 \cdot \frac{c}{b_2}\\ \mathbf{elif}\;b_2 \leq 1.6 \cdot 10^{-138}:\\ \;\;\;\;\frac{\sqrt{b_2 \cdot b_2 - a \cdot c} - b_2}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b_2} \cdot -0.5\\ \end{array} \]

Alternative 2: 80.6% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;b_2 \leq -3.25 \cdot 10^{-80}:\\ \;\;\;\;-2 \cdot \frac{b_2}{a} + 0.5 \cdot \frac{c}{b_2}\\ \mathbf{elif}\;b_2 \leq 2 \cdot 10^{-137}:\\ \;\;\;\;\frac{\sqrt{c \cdot \left(-a\right)} - b_2}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b_2} \cdot -0.5\\ \end{array} \end{array} \]
(FPCore (a b_2 c)
 :precision binary64
 (if (<= b_2 -3.25e-80)
   (+ (* -2.0 (/ b_2 a)) (* 0.5 (/ c b_2)))
   (if (<= b_2 2e-137) (/ (- (sqrt (* c (- a))) b_2) a) (* (/ c b_2) -0.5))))
double code(double a, double b_2, double c) {
	double tmp;
	if (b_2 <= -3.25e-80) {
		tmp = (-2.0 * (b_2 / a)) + (0.5 * (c / b_2));
	} else if (b_2 <= 2e-137) {
		tmp = (sqrt((c * -a)) - b_2) / a;
	} else {
		tmp = (c / b_2) * -0.5;
	}
	return tmp;
}
real(8) function code(a, b_2, c)
    real(8), intent (in) :: a
    real(8), intent (in) :: b_2
    real(8), intent (in) :: c
    real(8) :: tmp
    if (b_2 <= (-3.25d-80)) then
        tmp = ((-2.0d0) * (b_2 / a)) + (0.5d0 * (c / b_2))
    else if (b_2 <= 2d-137) then
        tmp = (sqrt((c * -a)) - b_2) / a
    else
        tmp = (c / b_2) * (-0.5d0)
    end if
    code = tmp
end function
public static double code(double a, double b_2, double c) {
	double tmp;
	if (b_2 <= -3.25e-80) {
		tmp = (-2.0 * (b_2 / a)) + (0.5 * (c / b_2));
	} else if (b_2 <= 2e-137) {
		tmp = (Math.sqrt((c * -a)) - b_2) / a;
	} else {
		tmp = (c / b_2) * -0.5;
	}
	return tmp;
}
def code(a, b_2, c):
	tmp = 0
	if b_2 <= -3.25e-80:
		tmp = (-2.0 * (b_2 / a)) + (0.5 * (c / b_2))
	elif b_2 <= 2e-137:
		tmp = (math.sqrt((c * -a)) - b_2) / a
	else:
		tmp = (c / b_2) * -0.5
	return tmp
function code(a, b_2, c)
	tmp = 0.0
	if (b_2 <= -3.25e-80)
		tmp = Float64(Float64(-2.0 * Float64(b_2 / a)) + Float64(0.5 * Float64(c / b_2)));
	elseif (b_2 <= 2e-137)
		tmp = Float64(Float64(sqrt(Float64(c * Float64(-a))) - b_2) / a);
	else
		tmp = Float64(Float64(c / b_2) * -0.5);
	end
	return tmp
end
function tmp_2 = code(a, b_2, c)
	tmp = 0.0;
	if (b_2 <= -3.25e-80)
		tmp = (-2.0 * (b_2 / a)) + (0.5 * (c / b_2));
	elseif (b_2 <= 2e-137)
		tmp = (sqrt((c * -a)) - b_2) / a;
	else
		tmp = (c / b_2) * -0.5;
	end
	tmp_2 = tmp;
end
code[a_, b$95$2_, c_] := If[LessEqual[b$95$2, -3.25e-80], N[(N[(-2.0 * N[(b$95$2 / a), $MachinePrecision]), $MachinePrecision] + N[(0.5 * N[(c / b$95$2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[b$95$2, 2e-137], N[(N[(N[Sqrt[N[(c * (-a)), $MachinePrecision]], $MachinePrecision] - b$95$2), $MachinePrecision] / a), $MachinePrecision], N[(N[(c / b$95$2), $MachinePrecision] * -0.5), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;b_2 \leq -3.25 \cdot 10^{-80}:\\
\;\;\;\;-2 \cdot \frac{b_2}{a} + 0.5 \cdot \frac{c}{b_2}\\

\mathbf{elif}\;b_2 \leq 2 \cdot 10^{-137}:\\
\;\;\;\;\frac{\sqrt{c \cdot \left(-a\right)} - b_2}{a}\\

\mathbf{else}:\\
\;\;\;\;\frac{c}{b_2} \cdot -0.5\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if b_2 < -3.24999999999999992e-80

    1. Initial program 71.3%

      \[\frac{\left(-b_2\right) + \sqrt{b_2 \cdot b_2 - a \cdot c}}{a} \]
    2. Step-by-step derivation
      1. +-commutative71.3%

        \[\leadsto \frac{\color{blue}{\sqrt{b_2 \cdot b_2 - a \cdot c} + \left(-b_2\right)}}{a} \]
      2. unsub-neg71.3%

        \[\leadsto \frac{\color{blue}{\sqrt{b_2 \cdot b_2 - a \cdot c} - b_2}}{a} \]
    3. Simplified71.3%

      \[\leadsto \color{blue}{\frac{\sqrt{b_2 \cdot b_2 - a \cdot c} - b_2}{a}} \]
    4. Taylor expanded in b_2 around -inf 90.3%

      \[\leadsto \color{blue}{-2 \cdot \frac{b_2}{a} + 0.5 \cdot \frac{c}{b_2}} \]

    if -3.24999999999999992e-80 < b_2 < 1.99999999999999996e-137

    1. Initial program 76.9%

      \[\frac{\left(-b_2\right) + \sqrt{b_2 \cdot b_2 - a \cdot c}}{a} \]
    2. Step-by-step derivation
      1. +-commutative76.9%

        \[\leadsto \frac{\color{blue}{\sqrt{b_2 \cdot b_2 - a \cdot c} + \left(-b_2\right)}}{a} \]
      2. unsub-neg76.9%

        \[\leadsto \frac{\color{blue}{\sqrt{b_2 \cdot b_2 - a \cdot c} - b_2}}{a} \]
    3. Simplified76.9%

      \[\leadsto \color{blue}{\frac{\sqrt{b_2 \cdot b_2 - a \cdot c} - b_2}{a}} \]
    4. Taylor expanded in b_2 around 0 75.6%

      \[\leadsto \frac{\sqrt{\color{blue}{-1 \cdot \left(c \cdot a\right)}} - b_2}{a} \]
    5. Step-by-step derivation
      1. mul-1-neg75.6%

        \[\leadsto \frac{\sqrt{\color{blue}{-c \cdot a}} - b_2}{a} \]
      2. distribute-rgt-neg-out75.6%

        \[\leadsto \frac{\sqrt{\color{blue}{c \cdot \left(-a\right)}} - b_2}{a} \]
    6. Simplified75.6%

      \[\leadsto \frac{\sqrt{\color{blue}{c \cdot \left(-a\right)}} - b_2}{a} \]

    if 1.99999999999999996e-137 < b_2

    1. Initial program 18.7%

      \[\frac{\left(-b_2\right) + \sqrt{b_2 \cdot b_2 - a \cdot c}}{a} \]
    2. Step-by-step derivation
      1. +-commutative18.7%

        \[\leadsto \frac{\color{blue}{\sqrt{b_2 \cdot b_2 - a \cdot c} + \left(-b_2\right)}}{a} \]
      2. unsub-neg18.7%

        \[\leadsto \frac{\color{blue}{\sqrt{b_2 \cdot b_2 - a \cdot c} - b_2}}{a} \]
    3. Simplified18.7%

      \[\leadsto \color{blue}{\frac{\sqrt{b_2 \cdot b_2 - a \cdot c} - b_2}{a}} \]
    4. Taylor expanded in b_2 around inf 85.8%

      \[\leadsto \color{blue}{-0.5 \cdot \frac{c}{b_2}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification84.9%

    \[\leadsto \begin{array}{l} \mathbf{if}\;b_2 \leq -3.25 \cdot 10^{-80}:\\ \;\;\;\;-2 \cdot \frac{b_2}{a} + 0.5 \cdot \frac{c}{b_2}\\ \mathbf{elif}\;b_2 \leq 2 \cdot 10^{-137}:\\ \;\;\;\;\frac{\sqrt{c \cdot \left(-a\right)} - b_2}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b_2} \cdot -0.5\\ \end{array} \]

Alternative 3: 67.8% accurate, 8.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;b_2 \leq -5 \cdot 10^{-310}:\\ \;\;\;\;-2 \cdot \frac{b_2}{a} + 0.5 \cdot \frac{c}{b_2}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b_2} \cdot -0.5\\ \end{array} \end{array} \]
(FPCore (a b_2 c)
 :precision binary64
 (if (<= b_2 -5e-310)
   (+ (* -2.0 (/ b_2 a)) (* 0.5 (/ c b_2)))
   (* (/ c b_2) -0.5)))
double code(double a, double b_2, double c) {
	double tmp;
	if (b_2 <= -5e-310) {
		tmp = (-2.0 * (b_2 / a)) + (0.5 * (c / b_2));
	} else {
		tmp = (c / b_2) * -0.5;
	}
	return tmp;
}
real(8) function code(a, b_2, c)
    real(8), intent (in) :: a
    real(8), intent (in) :: b_2
    real(8), intent (in) :: c
    real(8) :: tmp
    if (b_2 <= (-5d-310)) then
        tmp = ((-2.0d0) * (b_2 / a)) + (0.5d0 * (c / b_2))
    else
        tmp = (c / b_2) * (-0.5d0)
    end if
    code = tmp
end function
public static double code(double a, double b_2, double c) {
	double tmp;
	if (b_2 <= -5e-310) {
		tmp = (-2.0 * (b_2 / a)) + (0.5 * (c / b_2));
	} else {
		tmp = (c / b_2) * -0.5;
	}
	return tmp;
}
def code(a, b_2, c):
	tmp = 0
	if b_2 <= -5e-310:
		tmp = (-2.0 * (b_2 / a)) + (0.5 * (c / b_2))
	else:
		tmp = (c / b_2) * -0.5
	return tmp
function code(a, b_2, c)
	tmp = 0.0
	if (b_2 <= -5e-310)
		tmp = Float64(Float64(-2.0 * Float64(b_2 / a)) + Float64(0.5 * Float64(c / b_2)));
	else
		tmp = Float64(Float64(c / b_2) * -0.5);
	end
	return tmp
end
function tmp_2 = code(a, b_2, c)
	tmp = 0.0;
	if (b_2 <= -5e-310)
		tmp = (-2.0 * (b_2 / a)) + (0.5 * (c / b_2));
	else
		tmp = (c / b_2) * -0.5;
	end
	tmp_2 = tmp;
end
code[a_, b$95$2_, c_] := If[LessEqual[b$95$2, -5e-310], N[(N[(-2.0 * N[(b$95$2 / a), $MachinePrecision]), $MachinePrecision] + N[(0.5 * N[(c / b$95$2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(c / b$95$2), $MachinePrecision] * -0.5), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;b_2 \leq -5 \cdot 10^{-310}:\\
\;\;\;\;-2 \cdot \frac{b_2}{a} + 0.5 \cdot \frac{c}{b_2}\\

\mathbf{else}:\\
\;\;\;\;\frac{c}{b_2} \cdot -0.5\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if b_2 < -4.999999999999985e-310

    1. Initial program 73.5%

      \[\frac{\left(-b_2\right) + \sqrt{b_2 \cdot b_2 - a \cdot c}}{a} \]
    2. Step-by-step derivation
      1. +-commutative73.5%

        \[\leadsto \frac{\color{blue}{\sqrt{b_2 \cdot b_2 - a \cdot c} + \left(-b_2\right)}}{a} \]
      2. unsub-neg73.5%

        \[\leadsto \frac{\color{blue}{\sqrt{b_2 \cdot b_2 - a \cdot c} - b_2}}{a} \]
    3. Simplified73.5%

      \[\leadsto \color{blue}{\frac{\sqrt{b_2 \cdot b_2 - a \cdot c} - b_2}{a}} \]
    4. Taylor expanded in b_2 around -inf 70.0%

      \[\leadsto \color{blue}{-2 \cdot \frac{b_2}{a} + 0.5 \cdot \frac{c}{b_2}} \]

    if -4.999999999999985e-310 < b_2

    1. Initial program 33.5%

      \[\frac{\left(-b_2\right) + \sqrt{b_2 \cdot b_2 - a \cdot c}}{a} \]
    2. Step-by-step derivation
      1. +-commutative33.5%

        \[\leadsto \frac{\color{blue}{\sqrt{b_2 \cdot b_2 - a \cdot c} + \left(-b_2\right)}}{a} \]
      2. unsub-neg33.5%

        \[\leadsto \frac{\color{blue}{\sqrt{b_2 \cdot b_2 - a \cdot c} - b_2}}{a} \]
    3. Simplified33.5%

      \[\leadsto \color{blue}{\frac{\sqrt{b_2 \cdot b_2 - a \cdot c} - b_2}{a}} \]
    4. Taylor expanded in b_2 around inf 66.9%

      \[\leadsto \color{blue}{-0.5 \cdot \frac{c}{b_2}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification68.5%

    \[\leadsto \begin{array}{l} \mathbf{if}\;b_2 \leq -5 \cdot 10^{-310}:\\ \;\;\;\;-2 \cdot \frac{b_2}{a} + 0.5 \cdot \frac{c}{b_2}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b_2} \cdot -0.5\\ \end{array} \]

Alternative 4: 67.6% accurate, 15.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;b_2 \leq 3.6 \cdot 10^{-296}:\\ \;\;\;\;\frac{b_2 \cdot -2}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b_2} \cdot -0.5\\ \end{array} \end{array} \]
(FPCore (a b_2 c)
 :precision binary64
 (if (<= b_2 3.6e-296) (/ (* b_2 -2.0) a) (* (/ c b_2) -0.5)))
double code(double a, double b_2, double c) {
	double tmp;
	if (b_2 <= 3.6e-296) {
		tmp = (b_2 * -2.0) / a;
	} else {
		tmp = (c / b_2) * -0.5;
	}
	return tmp;
}
real(8) function code(a, b_2, c)
    real(8), intent (in) :: a
    real(8), intent (in) :: b_2
    real(8), intent (in) :: c
    real(8) :: tmp
    if (b_2 <= 3.6d-296) then
        tmp = (b_2 * (-2.0d0)) / a
    else
        tmp = (c / b_2) * (-0.5d0)
    end if
    code = tmp
end function
public static double code(double a, double b_2, double c) {
	double tmp;
	if (b_2 <= 3.6e-296) {
		tmp = (b_2 * -2.0) / a;
	} else {
		tmp = (c / b_2) * -0.5;
	}
	return tmp;
}
def code(a, b_2, c):
	tmp = 0
	if b_2 <= 3.6e-296:
		tmp = (b_2 * -2.0) / a
	else:
		tmp = (c / b_2) * -0.5
	return tmp
function code(a, b_2, c)
	tmp = 0.0
	if (b_2 <= 3.6e-296)
		tmp = Float64(Float64(b_2 * -2.0) / a);
	else
		tmp = Float64(Float64(c / b_2) * -0.5);
	end
	return tmp
end
function tmp_2 = code(a, b_2, c)
	tmp = 0.0;
	if (b_2 <= 3.6e-296)
		tmp = (b_2 * -2.0) / a;
	else
		tmp = (c / b_2) * -0.5;
	end
	tmp_2 = tmp;
end
code[a_, b$95$2_, c_] := If[LessEqual[b$95$2, 3.6e-296], N[(N[(b$95$2 * -2.0), $MachinePrecision] / a), $MachinePrecision], N[(N[(c / b$95$2), $MachinePrecision] * -0.5), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;b_2 \leq 3.6 \cdot 10^{-296}:\\
\;\;\;\;\frac{b_2 \cdot -2}{a}\\

\mathbf{else}:\\
\;\;\;\;\frac{c}{b_2} \cdot -0.5\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if b_2 < 3.5999999999999998e-296

    1. Initial program 74.1%

      \[\frac{\left(-b_2\right) + \sqrt{b_2 \cdot b_2 - a \cdot c}}{a} \]
    2. Step-by-step derivation
      1. +-commutative74.1%

        \[\leadsto \frac{\color{blue}{\sqrt{b_2 \cdot b_2 - a \cdot c} + \left(-b_2\right)}}{a} \]
      2. unsub-neg74.1%

        \[\leadsto \frac{\color{blue}{\sqrt{b_2 \cdot b_2 - a \cdot c} - b_2}}{a} \]
    3. Simplified74.1%

      \[\leadsto \color{blue}{\frac{\sqrt{b_2 \cdot b_2 - a \cdot c} - b_2}{a}} \]
    4. Taylor expanded in b_2 around -inf 68.3%

      \[\leadsto \frac{\color{blue}{-2 \cdot b_2}}{a} \]
    5. Step-by-step derivation
      1. *-commutative68.3%

        \[\leadsto \frac{\color{blue}{b_2 \cdot -2}}{a} \]
    6. Simplified68.3%

      \[\leadsto \frac{\color{blue}{b_2 \cdot -2}}{a} \]

    if 3.5999999999999998e-296 < b_2

    1. Initial program 31.9%

      \[\frac{\left(-b_2\right) + \sqrt{b_2 \cdot b_2 - a \cdot c}}{a} \]
    2. Step-by-step derivation
      1. +-commutative31.9%

        \[\leadsto \frac{\color{blue}{\sqrt{b_2 \cdot b_2 - a \cdot c} + \left(-b_2\right)}}{a} \]
      2. unsub-neg31.9%

        \[\leadsto \frac{\color{blue}{\sqrt{b_2 \cdot b_2 - a \cdot c} - b_2}}{a} \]
    3. Simplified31.9%

      \[\leadsto \color{blue}{\frac{\sqrt{b_2 \cdot b_2 - a \cdot c} - b_2}{a}} \]
    4. Taylor expanded in b_2 around inf 68.5%

      \[\leadsto \color{blue}{-0.5 \cdot \frac{c}{b_2}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification68.4%

    \[\leadsto \begin{array}{l} \mathbf{if}\;b_2 \leq 3.6 \cdot 10^{-296}:\\ \;\;\;\;\frac{b_2 \cdot -2}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b_2} \cdot -0.5\\ \end{array} \]

Alternative 5: 35.6% accurate, 22.4× speedup?

\[\begin{array}{l} \\ \frac{c}{b_2} \cdot -0.5 \end{array} \]
(FPCore (a b_2 c) :precision binary64 (* (/ c b_2) -0.5))
double code(double a, double b_2, double c) {
	return (c / b_2) * -0.5;
}
real(8) function code(a, b_2, c)
    real(8), intent (in) :: a
    real(8), intent (in) :: b_2
    real(8), intent (in) :: c
    code = (c / b_2) * (-0.5d0)
end function
public static double code(double a, double b_2, double c) {
	return (c / b_2) * -0.5;
}
def code(a, b_2, c):
	return (c / b_2) * -0.5
function code(a, b_2, c)
	return Float64(Float64(c / b_2) * -0.5)
end
function tmp = code(a, b_2, c)
	tmp = (c / b_2) * -0.5;
end
code[a_, b$95$2_, c_] := N[(N[(c / b$95$2), $MachinePrecision] * -0.5), $MachinePrecision]
\begin{array}{l}

\\
\frac{c}{b_2} \cdot -0.5
\end{array}
Derivation
  1. Initial program 54.5%

    \[\frac{\left(-b_2\right) + \sqrt{b_2 \cdot b_2 - a \cdot c}}{a} \]
  2. Step-by-step derivation
    1. +-commutative54.5%

      \[\leadsto \frac{\color{blue}{\sqrt{b_2 \cdot b_2 - a \cdot c} + \left(-b_2\right)}}{a} \]
    2. unsub-neg54.5%

      \[\leadsto \frac{\color{blue}{\sqrt{b_2 \cdot b_2 - a \cdot c} - b_2}}{a} \]
  3. Simplified54.5%

    \[\leadsto \color{blue}{\frac{\sqrt{b_2 \cdot b_2 - a \cdot c} - b_2}{a}} \]
  4. Taylor expanded in b_2 around inf 33.0%

    \[\leadsto \color{blue}{-0.5 \cdot \frac{c}{b_2}} \]
  5. Final simplification33.0%

    \[\leadsto \frac{c}{b_2} \cdot -0.5 \]

Reproduce

?
herbie shell --seed 2023201 
(FPCore (a b_2 c)
  :name "quad2p (problem 3.2.1, positive)"
  :precision binary64
  (/ (+ (- b_2) (sqrt (- (* b_2 b_2) (* a c)))) a))