quad2p (problem 3.2.1, positive)

Percentage Accurate: 51.2% → 85.2%
Time: 8.0s
Alternatives: 6
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 6 alternatives:

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

Initial Program: 51.2% 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 -4.8 \cdot 10^{+35}:\\ \;\;\;\;-2 \cdot \frac{b_2}{a} + 0.5 \cdot \frac{c}{b_2}\\ \mathbf{elif}\;b_2 \leq 6.5 \cdot 10^{-89}:\\ \;\;\;\;\frac{\sqrt{b_2 \cdot b_2 - a \cdot c} - b_2}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c \cdot -0.5}{b_2}\\ \end{array} \end{array} \]
(FPCore (a b_2 c)
 :precision binary64
 (if (<= b_2 -4.8e+35)
   (+ (* -2.0 (/ b_2 a)) (* 0.5 (/ c b_2)))
   (if (<= b_2 6.5e-89)
     (/ (- (sqrt (- (* b_2 b_2) (* a c))) b_2) a)
     (/ (* c -0.5) b_2))))
double code(double a, double b_2, double c) {
	double tmp;
	if (b_2 <= -4.8e+35) {
		tmp = (-2.0 * (b_2 / a)) + (0.5 * (c / b_2));
	} else if (b_2 <= 6.5e-89) {
		tmp = (sqrt(((b_2 * b_2) - (a * c))) - b_2) / a;
	} else {
		tmp = (c * -0.5) / b_2;
	}
	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 <= (-4.8d+35)) then
        tmp = ((-2.0d0) * (b_2 / a)) + (0.5d0 * (c / b_2))
    else if (b_2 <= 6.5d-89) then
        tmp = (sqrt(((b_2 * b_2) - (a * c))) - b_2) / a
    else
        tmp = (c * (-0.5d0)) / b_2
    end if
    code = tmp
end function
public static double code(double a, double b_2, double c) {
	double tmp;
	if (b_2 <= -4.8e+35) {
		tmp = (-2.0 * (b_2 / a)) + (0.5 * (c / b_2));
	} else if (b_2 <= 6.5e-89) {
		tmp = (Math.sqrt(((b_2 * b_2) - (a * c))) - b_2) / a;
	} else {
		tmp = (c * -0.5) / b_2;
	}
	return tmp;
}
def code(a, b_2, c):
	tmp = 0
	if b_2 <= -4.8e+35:
		tmp = (-2.0 * (b_2 / a)) + (0.5 * (c / b_2))
	elif b_2 <= 6.5e-89:
		tmp = (math.sqrt(((b_2 * b_2) - (a * c))) - b_2) / a
	else:
		tmp = (c * -0.5) / b_2
	return tmp
function code(a, b_2, c)
	tmp = 0.0
	if (b_2 <= -4.8e+35)
		tmp = Float64(Float64(-2.0 * Float64(b_2 / a)) + Float64(0.5 * Float64(c / b_2)));
	elseif (b_2 <= 6.5e-89)
		tmp = Float64(Float64(sqrt(Float64(Float64(b_2 * b_2) - Float64(a * c))) - b_2) / a);
	else
		tmp = Float64(Float64(c * -0.5) / b_2);
	end
	return tmp
end
function tmp_2 = code(a, b_2, c)
	tmp = 0.0;
	if (b_2 <= -4.8e+35)
		tmp = (-2.0 * (b_2 / a)) + (0.5 * (c / b_2));
	elseif (b_2 <= 6.5e-89)
		tmp = (sqrt(((b_2 * b_2) - (a * c))) - b_2) / a;
	else
		tmp = (c * -0.5) / b_2;
	end
	tmp_2 = tmp;
end
code[a_, b$95$2_, c_] := If[LessEqual[b$95$2, -4.8e+35], 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, 6.5e-89], 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 * -0.5), $MachinePrecision] / b$95$2), $MachinePrecision]]]
\begin{array}{l}

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

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

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


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

    1. Initial program 58.6%

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

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

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

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

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

    if -4.80000000000000029e35 < b_2 < 6.50000000000000034e-89

    1. Initial program 75.3%

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

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

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

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

    if 6.50000000000000034e-89 < b_2

    1. Initial program 22.6%

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

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

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

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

      \[\leadsto \frac{\color{blue}{-0.5 \cdot \frac{c \cdot a}{b_2}}}{a} \]
    5. Taylor expanded in c around 0 84.4%

      \[\leadsto \color{blue}{-0.5 \cdot \frac{c}{b_2}} \]
    6. Step-by-step derivation
      1. associate-*r/84.5%

        \[\leadsto \color{blue}{\frac{-0.5 \cdot c}{b_2}} \]
    7. Simplified84.5%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b_2 \leq -4.8 \cdot 10^{+35}:\\ \;\;\;\;-2 \cdot \frac{b_2}{a} + 0.5 \cdot \frac{c}{b_2}\\ \mathbf{elif}\;b_2 \leq 6.5 \cdot 10^{-89}:\\ \;\;\;\;\frac{\sqrt{b_2 \cdot b_2 - a \cdot c} - b_2}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c \cdot -0.5}{b_2}\\ \end{array} \]

Alternative 2: 80.6% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{\sqrt{a \cdot \left(-c\right)} - b_2}{a}\\ t_1 := -2 \cdot \frac{b_2}{a} + 0.5 \cdot \frac{c}{b_2}\\ \mathbf{if}\;b_2 \leq -2.4 \cdot 10^{-13}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;b_2 \leq -7.5 \cdot 10^{-43}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;b_2 \leq -1.4 \cdot 10^{-100}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;b_2 \leq 4.5 \cdot 10^{-89}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\frac{c \cdot -0.5}{b_2}\\ \end{array} \end{array} \]
(FPCore (a b_2 c)
 :precision binary64
 (let* ((t_0 (/ (- (sqrt (* a (- c))) b_2) a))
        (t_1 (+ (* -2.0 (/ b_2 a)) (* 0.5 (/ c b_2)))))
   (if (<= b_2 -2.4e-13)
     t_1
     (if (<= b_2 -7.5e-43)
       t_0
       (if (<= b_2 -1.4e-100)
         t_1
         (if (<= b_2 4.5e-89) t_0 (/ (* c -0.5) b_2)))))))
double code(double a, double b_2, double c) {
	double t_0 = (sqrt((a * -c)) - b_2) / a;
	double t_1 = (-2.0 * (b_2 / a)) + (0.5 * (c / b_2));
	double tmp;
	if (b_2 <= -2.4e-13) {
		tmp = t_1;
	} else if (b_2 <= -7.5e-43) {
		tmp = t_0;
	} else if (b_2 <= -1.4e-100) {
		tmp = t_1;
	} else if (b_2 <= 4.5e-89) {
		tmp = t_0;
	} else {
		tmp = (c * -0.5) / b_2;
	}
	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) :: t_0
    real(8) :: t_1
    real(8) :: tmp
    t_0 = (sqrt((a * -c)) - b_2) / a
    t_1 = ((-2.0d0) * (b_2 / a)) + (0.5d0 * (c / b_2))
    if (b_2 <= (-2.4d-13)) then
        tmp = t_1
    else if (b_2 <= (-7.5d-43)) then
        tmp = t_0
    else if (b_2 <= (-1.4d-100)) then
        tmp = t_1
    else if (b_2 <= 4.5d-89) then
        tmp = t_0
    else
        tmp = (c * (-0.5d0)) / b_2
    end if
    code = tmp
end function
public static double code(double a, double b_2, double c) {
	double t_0 = (Math.sqrt((a * -c)) - b_2) / a;
	double t_1 = (-2.0 * (b_2 / a)) + (0.5 * (c / b_2));
	double tmp;
	if (b_2 <= -2.4e-13) {
		tmp = t_1;
	} else if (b_2 <= -7.5e-43) {
		tmp = t_0;
	} else if (b_2 <= -1.4e-100) {
		tmp = t_1;
	} else if (b_2 <= 4.5e-89) {
		tmp = t_0;
	} else {
		tmp = (c * -0.5) / b_2;
	}
	return tmp;
}
def code(a, b_2, c):
	t_0 = (math.sqrt((a * -c)) - b_2) / a
	t_1 = (-2.0 * (b_2 / a)) + (0.5 * (c / b_2))
	tmp = 0
	if b_2 <= -2.4e-13:
		tmp = t_1
	elif b_2 <= -7.5e-43:
		tmp = t_0
	elif b_2 <= -1.4e-100:
		tmp = t_1
	elif b_2 <= 4.5e-89:
		tmp = t_0
	else:
		tmp = (c * -0.5) / b_2
	return tmp
function code(a, b_2, c)
	t_0 = Float64(Float64(sqrt(Float64(a * Float64(-c))) - b_2) / a)
	t_1 = Float64(Float64(-2.0 * Float64(b_2 / a)) + Float64(0.5 * Float64(c / b_2)))
	tmp = 0.0
	if (b_2 <= -2.4e-13)
		tmp = t_1;
	elseif (b_2 <= -7.5e-43)
		tmp = t_0;
	elseif (b_2 <= -1.4e-100)
		tmp = t_1;
	elseif (b_2 <= 4.5e-89)
		tmp = t_0;
	else
		tmp = Float64(Float64(c * -0.5) / b_2);
	end
	return tmp
end
function tmp_2 = code(a, b_2, c)
	t_0 = (sqrt((a * -c)) - b_2) / a;
	t_1 = (-2.0 * (b_2 / a)) + (0.5 * (c / b_2));
	tmp = 0.0;
	if (b_2 <= -2.4e-13)
		tmp = t_1;
	elseif (b_2 <= -7.5e-43)
		tmp = t_0;
	elseif (b_2 <= -1.4e-100)
		tmp = t_1;
	elseif (b_2 <= 4.5e-89)
		tmp = t_0;
	else
		tmp = (c * -0.5) / b_2;
	end
	tmp_2 = tmp;
end
code[a_, b$95$2_, c_] := Block[{t$95$0 = N[(N[(N[Sqrt[N[(a * (-c)), $MachinePrecision]], $MachinePrecision] - b$95$2), $MachinePrecision] / a), $MachinePrecision]}, Block[{t$95$1 = 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, -2.4e-13], t$95$1, If[LessEqual[b$95$2, -7.5e-43], t$95$0, If[LessEqual[b$95$2, -1.4e-100], t$95$1, If[LessEqual[b$95$2, 4.5e-89], t$95$0, N[(N[(c * -0.5), $MachinePrecision] / b$95$2), $MachinePrecision]]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \frac{\sqrt{a \cdot \left(-c\right)} - b_2}{a}\\
t_1 := -2 \cdot \frac{b_2}{a} + 0.5 \cdot \frac{c}{b_2}\\
\mathbf{if}\;b_2 \leq -2.4 \cdot 10^{-13}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;b_2 \leq -7.5 \cdot 10^{-43}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;b_2 \leq -1.4 \cdot 10^{-100}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;b_2 \leq 4.5 \cdot 10^{-89}:\\
\;\;\;\;t_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if b_2 < -2.3999999999999999e-13 or -7.50000000000000068e-43 < b_2 < -1.39999999999999998e-100

    1. Initial program 66.5%

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

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

        \[\leadsto \frac{\color{blue}{\sqrt{b_2 \cdot b_2 - a \cdot c} - b_2}}{a} \]
    3. Simplified66.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 90.8%

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

    if -2.3999999999999999e-13 < b_2 < -7.50000000000000068e-43 or -1.39999999999999998e-100 < b_2 < 4.4999999999999999e-89

    1. Initial program 70.8%

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

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

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

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

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

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

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

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

    if 4.4999999999999999e-89 < b_2

    1. Initial program 22.6%

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

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

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

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

      \[\leadsto \frac{\color{blue}{-0.5 \cdot \frac{c \cdot a}{b_2}}}{a} \]
    5. Taylor expanded in c around 0 84.4%

      \[\leadsto \color{blue}{-0.5 \cdot \frac{c}{b_2}} \]
    6. Step-by-step derivation
      1. associate-*r/84.5%

        \[\leadsto \color{blue}{\frac{-0.5 \cdot c}{b_2}} \]
    7. Simplified84.5%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b_2 \leq -2.4 \cdot 10^{-13}:\\ \;\;\;\;-2 \cdot \frac{b_2}{a} + 0.5 \cdot \frac{c}{b_2}\\ \mathbf{elif}\;b_2 \leq -7.5 \cdot 10^{-43}:\\ \;\;\;\;\frac{\sqrt{a \cdot \left(-c\right)} - b_2}{a}\\ \mathbf{elif}\;b_2 \leq -1.4 \cdot 10^{-100}:\\ \;\;\;\;-2 \cdot \frac{b_2}{a} + 0.5 \cdot \frac{c}{b_2}\\ \mathbf{elif}\;b_2 \leq 4.5 \cdot 10^{-89}:\\ \;\;\;\;\frac{\sqrt{a \cdot \left(-c\right)} - b_2}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c \cdot -0.5}{b_2}\\ \end{array} \]

Alternative 3: 68.6% 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 \cdot -0.5}{b_2}\\ \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 -0.5) b_2)))
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 * -0.5) / b_2;
	}
	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 * (-0.5d0)) / b_2
    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 * -0.5) / b_2;
	}
	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 * -0.5) / b_2
	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 * -0.5) / b_2);
	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 * -0.5) / b_2;
	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 * -0.5), $MachinePrecision] / b$95$2), $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 \cdot -0.5}{b_2}\\


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

    1. Initial program 68.5%

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

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

        \[\leadsto \frac{\color{blue}{\sqrt{b_2 \cdot b_2 - a \cdot c} - b_2}}{a} \]
    3. Simplified68.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 69.1%

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

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

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

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

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

      \[\leadsto \frac{\color{blue}{-0.5 \cdot \frac{c \cdot a}{b_2}}}{a} \]
    5. Taylor expanded in c around 0 69.6%

      \[\leadsto \color{blue}{-0.5 \cdot \frac{c}{b_2}} \]
    6. Step-by-step derivation
      1. associate-*r/69.7%

        \[\leadsto \color{blue}{\frac{-0.5 \cdot c}{b_2}} \]
    7. Simplified69.7%

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

    \[\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 \cdot -0.5}{b_2}\\ \end{array} \]

Alternative 4: 68.4% accurate, 15.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;b_2 \leq 8.8 \cdot 10^{-242}:\\ \;\;\;\;-2 \cdot \frac{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 8.8e-242) (* -2.0 (/ b_2 a)) (* (/ c b_2) -0.5)))
double code(double a, double b_2, double c) {
	double tmp;
	if (b_2 <= 8.8e-242) {
		tmp = -2.0 * (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 <= 8.8d-242) then
        tmp = (-2.0d0) * (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 <= 8.8e-242) {
		tmp = -2.0 * (b_2 / a);
	} else {
		tmp = (c / b_2) * -0.5;
	}
	return tmp;
}
def code(a, b_2, c):
	tmp = 0
	if b_2 <= 8.8e-242:
		tmp = -2.0 * (b_2 / a)
	else:
		tmp = (c / b_2) * -0.5
	return tmp
function code(a, b_2, c)
	tmp = 0.0
	if (b_2 <= 8.8e-242)
		tmp = Float64(-2.0 * Float64(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 <= 8.8e-242)
		tmp = -2.0 * (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, 8.8e-242], N[(-2.0 * N[(b$95$2 / a), $MachinePrecision]), $MachinePrecision], N[(N[(c / b$95$2), $MachinePrecision] * -0.5), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;b_2 \leq 8.8 \cdot 10^{-242}:\\
\;\;\;\;-2 \cdot \frac{b_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 < 8.80000000000000006e-242

    1. Initial program 69.5%

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

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

        \[\leadsto \frac{\color{blue}{\sqrt{b_2 \cdot b_2 - a \cdot c} - b_2}}{a} \]
    3. Simplified69.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 65.1%

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

    if 8.80000000000000006e-242 < b_2

    1. Initial program 29.2%

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

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

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

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

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

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

Alternative 5: 68.4% accurate, 15.9× speedup?

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

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

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


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

    1. Initial program 69.5%

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

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

        \[\leadsto \frac{\color{blue}{\sqrt{b_2 \cdot b_2 - a \cdot c} - b_2}}{a} \]
    3. Simplified69.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 65.1%

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

    if 8.80000000000000006e-242 < b_2

    1. Initial program 29.2%

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

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

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

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

      \[\leadsto \frac{\color{blue}{-0.5 \cdot \frac{c \cdot a}{b_2}}}{a} \]
    5. Taylor expanded in c around 0 73.1%

      \[\leadsto \color{blue}{-0.5 \cdot \frac{c}{b_2}} \]
    6. Step-by-step derivation
      1. associate-*r/73.2%

        \[\leadsto \color{blue}{\frac{-0.5 \cdot c}{b_2}} \]
    7. Simplified73.2%

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

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

Alternative 6: 35.4% accurate, 22.4× speedup?

\[\begin{array}{l} \\ -2 \cdot \frac{b_2}{a} \end{array} \]
(FPCore (a b_2 c) :precision binary64 (* -2.0 (/ b_2 a)))
double code(double a, double b_2, double c) {
	return -2.0 * (b_2 / 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 = (-2.0d0) * (b_2 / a)
end function
public static double code(double a, double b_2, double c) {
	return -2.0 * (b_2 / a);
}
def code(a, b_2, c):
	return -2.0 * (b_2 / a)
function code(a, b_2, c)
	return Float64(-2.0 * Float64(b_2 / a))
end
function tmp = code(a, b_2, c)
	tmp = -2.0 * (b_2 / a);
end
code[a_, b$95$2_, c_] := N[(-2.0 * N[(b$95$2 / a), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
-2 \cdot \frac{b_2}{a}
\end{array}
Derivation
  1. Initial program 48.5%

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

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

      \[\leadsto \frac{\color{blue}{\sqrt{b_2 \cdot b_2 - a \cdot c} - b_2}}{a} \]
  3. Simplified48.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 32.6%

    \[\leadsto \color{blue}{-2 \cdot \frac{b_2}{a}} \]
  5. Final simplification32.6%

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

Reproduce

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