quad2m (problem 3.2.1, negative)

Percentage Accurate: 51.4% → 83.6%
Time: 10.1s
Alternatives: 9
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 9 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.4% 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: 83.6% accurate, 0.9× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;b_2 \leq -6.8 \cdot 10^{-76}:\\
\;\;\;\;\frac{-0.5 \cdot c}{b_2}\\

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

\mathbf{else}:\\
\;\;\;\;\frac{\left(-b_2\right) - \left(b_2 + -0.5 \cdot \frac{c}{\frac{b_2}{a}}\right)}{a}\\


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

    1. Initial program 16.3%

      \[\frac{\left(-b_2\right) - \sqrt{b_2 \cdot b_2 - a \cdot c}}{a} \]
    2. Taylor expanded in b_2 around -inf 87.5%

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

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

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

    if -6.7999999999999998e-76 < b_2 < 1.04999999999999996e-17

    1. Initial program 81.6%

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

        \[\leadsto \color{blue}{\frac{-b_2}{a} - \frac{\sqrt{b_2 \cdot b_2 - a \cdot c}}{a}} \]
      2. neg-mul-181.6%

        \[\leadsto \frac{\color{blue}{-1 \cdot b_2}}{a} - \frac{\sqrt{b_2 \cdot b_2 - a \cdot c}}{a} \]
      3. *-un-lft-identity81.6%

        \[\leadsto \frac{-1 \cdot b_2}{\color{blue}{1 \cdot a}} - \frac{\sqrt{b_2 \cdot b_2 - a \cdot c}}{a} \]
      4. times-frac81.6%

        \[\leadsto \color{blue}{\frac{-1}{1} \cdot \frac{b_2}{a}} - \frac{\sqrt{b_2 \cdot b_2 - a \cdot c}}{a} \]
      5. metadata-eval81.6%

        \[\leadsto \color{blue}{-1} \cdot \frac{b_2}{a} - \frac{\sqrt{b_2 \cdot b_2 - a \cdot c}}{a} \]
      6. add-sqr-sqrt50.9%

        \[\leadsto -1 \cdot \frac{\color{blue}{\sqrt{b_2} \cdot \sqrt{b_2}}}{a} - \frac{\sqrt{b_2 \cdot b_2 - a \cdot c}}{a} \]
      7. sqrt-prod80.6%

        \[\leadsto -1 \cdot \frac{\color{blue}{\sqrt{b_2 \cdot b_2}}}{a} - \frac{\sqrt{b_2 \cdot b_2 - a \cdot c}}{a} \]
      8. sqr-neg80.6%

        \[\leadsto -1 \cdot \frac{\sqrt{\color{blue}{\left(-b_2\right) \cdot \left(-b_2\right)}}}{a} - \frac{\sqrt{b_2 \cdot b_2 - a \cdot c}}{a} \]
      9. sqrt-unprod30.5%

        \[\leadsto -1 \cdot \frac{\color{blue}{\sqrt{-b_2} \cdot \sqrt{-b_2}}}{a} - \frac{\sqrt{b_2 \cdot b_2 - a \cdot c}}{a} \]
      10. add-sqr-sqrt68.6%

        \[\leadsto -1 \cdot \frac{\color{blue}{-b_2}}{a} - \frac{\sqrt{b_2 \cdot b_2 - a \cdot c}}{a} \]
      11. fma-neg68.6%

        \[\leadsto \color{blue}{\mathsf{fma}\left(-1, \frac{-b_2}{a}, -\frac{\sqrt{b_2 \cdot b_2 - a \cdot c}}{a}\right)} \]
      12. add-sqr-sqrt30.5%

        \[\leadsto \mathsf{fma}\left(-1, \frac{\color{blue}{\sqrt{-b_2} \cdot \sqrt{-b_2}}}{a}, -\frac{\sqrt{b_2 \cdot b_2 - a \cdot c}}{a}\right) \]
      13. sqrt-unprod80.6%

        \[\leadsto \mathsf{fma}\left(-1, \frac{\color{blue}{\sqrt{\left(-b_2\right) \cdot \left(-b_2\right)}}}{a}, -\frac{\sqrt{b_2 \cdot b_2 - a \cdot c}}{a}\right) \]
      14. sqr-neg80.6%

        \[\leadsto \mathsf{fma}\left(-1, \frac{\sqrt{\color{blue}{b_2 \cdot b_2}}}{a}, -\frac{\sqrt{b_2 \cdot b_2 - a \cdot c}}{a}\right) \]
      15. sqrt-prod50.9%

        \[\leadsto \mathsf{fma}\left(-1, \frac{\color{blue}{\sqrt{b_2} \cdot \sqrt{b_2}}}{a}, -\frac{\sqrt{b_2 \cdot b_2 - a \cdot c}}{a}\right) \]
      16. add-sqr-sqrt81.6%

        \[\leadsto \mathsf{fma}\left(-1, \frac{\color{blue}{b_2}}{a}, -\frac{\sqrt{b_2 \cdot b_2 - a \cdot c}}{a}\right) \]
    3. Applied egg-rr78.6%

      \[\leadsto \color{blue}{\mathsf{fma}\left(-1, \frac{b_2}{a}, -\frac{\mathsf{hypot}\left(b_2, \sqrt{c \cdot \left(-a\right)}\right)}{a}\right)} \]
    4. Step-by-step derivation
      1. fma-neg78.6%

        \[\leadsto \color{blue}{-1 \cdot \frac{b_2}{a} - \frac{\mathsf{hypot}\left(b_2, \sqrt{c \cdot \left(-a\right)}\right)}{a}} \]
      2. associate-*r/78.6%

        \[\leadsto \color{blue}{\frac{-1 \cdot b_2}{a}} - \frac{\mathsf{hypot}\left(b_2, \sqrt{c \cdot \left(-a\right)}\right)}{a} \]
      3. mul-1-neg78.6%

        \[\leadsto \frac{\color{blue}{-b_2}}{a} - \frac{\mathsf{hypot}\left(b_2, \sqrt{c \cdot \left(-a\right)}\right)}{a} \]
    5. Simplified78.6%

      \[\leadsto \color{blue}{\frac{-b_2}{a} - \frac{\mathsf{hypot}\left(b_2, \sqrt{c \cdot \left(-a\right)}\right)}{a}} \]
    6. Step-by-step derivation
      1. hypot-udef75.9%

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

        \[\leadsto \frac{-b_2}{a} - \frac{\sqrt{\color{blue}{\sqrt{b_2 \cdot b_2 + \sqrt{c \cdot \left(-a\right)} \cdot \sqrt{c \cdot \left(-a\right)}} \cdot \sqrt{b_2 \cdot b_2 + \sqrt{c \cdot \left(-a\right)} \cdot \sqrt{c \cdot \left(-a\right)}}}}}{a} \]
      3. hypot-udef75.9%

        \[\leadsto \frac{-b_2}{a} - \frac{\sqrt{\color{blue}{\mathsf{hypot}\left(b_2, \sqrt{c \cdot \left(-a\right)}\right)} \cdot \sqrt{b_2 \cdot b_2 + \sqrt{c \cdot \left(-a\right)} \cdot \sqrt{c \cdot \left(-a\right)}}}}{a} \]
      4. hypot-udef75.9%

        \[\leadsto \frac{-b_2}{a} - \frac{\sqrt{\mathsf{hypot}\left(b_2, \sqrt{c \cdot \left(-a\right)}\right) \cdot \color{blue}{\mathsf{hypot}\left(b_2, \sqrt{c \cdot \left(-a\right)}\right)}}}{a} \]
      5. pow1/275.9%

        \[\leadsto \frac{-b_2}{a} - \frac{\color{blue}{{\left(\mathsf{hypot}\left(b_2, \sqrt{c \cdot \left(-a\right)}\right) \cdot \mathsf{hypot}\left(b_2, \sqrt{c \cdot \left(-a\right)}\right)\right)}^{0.5}}}{a} \]
      6. hypot-udef75.9%

        \[\leadsto \frac{-b_2}{a} - \frac{{\left(\color{blue}{\sqrt{b_2 \cdot b_2 + \sqrt{c \cdot \left(-a\right)} \cdot \sqrt{c \cdot \left(-a\right)}}} \cdot \mathsf{hypot}\left(b_2, \sqrt{c \cdot \left(-a\right)}\right)\right)}^{0.5}}{a} \]
      7. hypot-udef75.9%

        \[\leadsto \frac{-b_2}{a} - \frac{{\left(\sqrt{b_2 \cdot b_2 + \sqrt{c \cdot \left(-a\right)} \cdot \sqrt{c \cdot \left(-a\right)}} \cdot \color{blue}{\sqrt{b_2 \cdot b_2 + \sqrt{c \cdot \left(-a\right)} \cdot \sqrt{c \cdot \left(-a\right)}}}\right)}^{0.5}}{a} \]
      8. add-sqr-sqrt75.9%

        \[\leadsto \frac{-b_2}{a} - \frac{{\color{blue}{\left(b_2 \cdot b_2 + \sqrt{c \cdot \left(-a\right)} \cdot \sqrt{c \cdot \left(-a\right)}\right)}}^{0.5}}{a} \]
      9. add-sqr-sqrt81.6%

        \[\leadsto \frac{-b_2}{a} - \frac{{\left(b_2 \cdot b_2 + \color{blue}{c \cdot \left(-a\right)}\right)}^{0.5}}{a} \]
      10. fma-def81.6%

        \[\leadsto \frac{-b_2}{a} - \frac{{\color{blue}{\left(\mathsf{fma}\left(b_2, b_2, c \cdot \left(-a\right)\right)\right)}}^{0.5}}{a} \]
      11. *-commutative81.6%

        \[\leadsto \frac{-b_2}{a} - \frac{{\left(\mathsf{fma}\left(b_2, b_2, \color{blue}{\left(-a\right) \cdot c}\right)\right)}^{0.5}}{a} \]
    7. Applied egg-rr81.6%

      \[\leadsto \frac{-b_2}{a} - \frac{\color{blue}{{\left(\mathsf{fma}\left(b_2, b_2, \left(-a\right) \cdot c\right)\right)}^{0.5}}}{a} \]
    8. Step-by-step derivation
      1. unpow1/281.6%

        \[\leadsto \frac{-b_2}{a} - \frac{\color{blue}{\sqrt{\mathsf{fma}\left(b_2, b_2, \left(-a\right) \cdot c\right)}}}{a} \]
      2. fma-udef81.6%

        \[\leadsto \frac{-b_2}{a} - \frac{\sqrt{\color{blue}{b_2 \cdot b_2 + \left(-a\right) \cdot c}}}{a} \]
      3. distribute-lft-neg-out81.6%

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

        \[\leadsto \frac{-b_2}{a} - \frac{\sqrt{\color{blue}{b_2 \cdot b_2 - a \cdot c}}}{a} \]
      5. *-commutative81.6%

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

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

    if 1.04999999999999996e-17 < b_2

    1. Initial program 67.4%

      \[\frac{\left(-b_2\right) - \sqrt{b_2 \cdot b_2 - a \cdot c}}{a} \]
    2. Taylor expanded in b_2 around inf 84.2%

      \[\leadsto \frac{\left(-b_2\right) - \color{blue}{\left(b_2 + -0.5 \cdot \frac{c \cdot a}{b_2}\right)}}{a} \]
    3. Step-by-step derivation
      1. associate-/l*94.6%

        \[\leadsto \frac{\left(-b_2\right) - \left(b_2 + -0.5 \cdot \color{blue}{\frac{c}{\frac{b_2}{a}}}\right)}{a} \]
    4. Simplified94.6%

      \[\leadsto \frac{\left(-b_2\right) - \color{blue}{\left(b_2 + -0.5 \cdot \frac{c}{\frac{b_2}{a}}\right)}}{a} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification87.4%

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

Alternative 2: 83.6% accurate, 1.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;b_2 \leq -6.8 \cdot 10^{-76}:\\
\;\;\;\;\frac{-0.5 \cdot c}{b_2}\\

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

\mathbf{else}:\\
\;\;\;\;\frac{\left(-b_2\right) - \left(b_2 + -0.5 \cdot \frac{c}{\frac{b_2}{a}}\right)}{a}\\


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

    1. Initial program 16.3%

      \[\frac{\left(-b_2\right) - \sqrt{b_2 \cdot b_2 - a \cdot c}}{a} \]
    2. Taylor expanded in b_2 around -inf 87.5%

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

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

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

    if -6.7999999999999998e-76 < b_2 < 1.04999999999999996e-17

    1. Initial program 81.6%

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

    if 1.04999999999999996e-17 < b_2

    1. Initial program 67.4%

      \[\frac{\left(-b_2\right) - \sqrt{b_2 \cdot b_2 - a \cdot c}}{a} \]
    2. Taylor expanded in b_2 around inf 84.2%

      \[\leadsto \frac{\left(-b_2\right) - \color{blue}{\left(b_2 + -0.5 \cdot \frac{c \cdot a}{b_2}\right)}}{a} \]
    3. Step-by-step derivation
      1. associate-/l*94.6%

        \[\leadsto \frac{\left(-b_2\right) - \left(b_2 + -0.5 \cdot \color{blue}{\frac{c}{\frac{b_2}{a}}}\right)}{a} \]
    4. Simplified94.6%

      \[\leadsto \frac{\left(-b_2\right) - \color{blue}{\left(b_2 + -0.5 \cdot \frac{c}{\frac{b_2}{a}}\right)}}{a} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification87.4%

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

Alternative 3: 80.3% accurate, 1.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;b_2 \leq -6.8 \cdot 10^{-76}:\\
\;\;\;\;\frac{-0.5 \cdot c}{b_2}\\

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

\mathbf{else}:\\
\;\;\;\;\frac{\left(-b_2\right) - \left(b_2 + -0.5 \cdot \frac{c}{\frac{b_2}{a}}\right)}{a}\\


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

    1. Initial program 16.3%

      \[\frac{\left(-b_2\right) - \sqrt{b_2 \cdot b_2 - a \cdot c}}{a} \]
    2. Taylor expanded in b_2 around -inf 87.5%

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

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

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

    if -6.7999999999999998e-76 < b_2 < 2.1999999999999999e-95

    1. Initial program 77.2%

      \[\frac{\left(-b_2\right) - \sqrt{b_2 \cdot b_2 - a \cdot c}}{a} \]
    2. Taylor expanded in b_2 around 0 75.5%

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

        \[\leadsto \frac{\left(-b_2\right) - \sqrt{\color{blue}{-c \cdot a}}}{a} \]
      2. distribute-rgt-neg-out75.5%

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

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

    if 2.1999999999999999e-95 < b_2

    1. Initial program 73.8%

      \[\frac{\left(-b_2\right) - \sqrt{b_2 \cdot b_2 - a \cdot c}}{a} \]
    2. Taylor expanded in b_2 around inf 79.1%

      \[\leadsto \frac{\left(-b_2\right) - \color{blue}{\left(b_2 + -0.5 \cdot \frac{c \cdot a}{b_2}\right)}}{a} \]
    3. Step-by-step derivation
      1. associate-/l*87.5%

        \[\leadsto \frac{\left(-b_2\right) - \left(b_2 + -0.5 \cdot \color{blue}{\frac{c}{\frac{b_2}{a}}}\right)}{a} \]
    4. Simplified87.5%

      \[\leadsto \frac{\left(-b_2\right) - \color{blue}{\left(b_2 + -0.5 \cdot \frac{c}{\frac{b_2}{a}}\right)}}{a} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification84.0%

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

Alternative 4: 68.1% accurate, 8.6× speedup?

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

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

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


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

    1. Initial program 33.8%

      \[\frac{\left(-b_2\right) - \sqrt{b_2 \cdot b_2 - a \cdot c}}{a} \]
    2. Taylor expanded in b_2 around -inf 67.2%

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

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

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

    if -1.999999999999994e-310 < b_2

    1. Initial program 75.4%

      \[\frac{\left(-b_2\right) - \sqrt{b_2 \cdot b_2 - a \cdot c}}{a} \]
    2. Taylor expanded in b_2 around inf 66.9%

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

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

Alternative 5: 42.9% accurate, 15.9× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;b_2 \leq -10500000000000:\\
\;\;\;\;0.5 \cdot \frac{c}{b_2}\\

\mathbf{else}:\\
\;\;\;\;b_2 \cdot \frac{-2}{a}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if b_2 < -1.05e13

    1. Initial program 14.3%

      \[\frac{\left(-b_2\right) - \sqrt{b_2 \cdot b_2 - a \cdot c}}{a} \]
    2. Taylor expanded in b_2 around inf 2.4%

      \[\leadsto \frac{\color{blue}{-2 \cdot b_2 + 0.5 \cdot \frac{c \cdot a}{b_2}}}{a} \]
    3. Taylor expanded in b_2 around 0 36.3%

      \[\leadsto \color{blue}{0.5 \cdot \frac{c}{b_2}} \]

    if -1.05e13 < b_2

    1. Initial program 72.5%

      \[\frac{\left(-b_2\right) - \sqrt{b_2 \cdot b_2 - a \cdot c}}{a} \]
    2. Taylor expanded in b_2 around inf 49.0%

      \[\leadsto \color{blue}{-2 \cdot \frac{b_2}{a} + 0.5 \cdot \frac{c}{b_2}} \]
    3. Taylor expanded in b_2 around inf 49.3%

      \[\leadsto \color{blue}{-2 \cdot \frac{b_2}{a}} \]
    4. Step-by-step derivation
      1. associate-*r/49.3%

        \[\leadsto \color{blue}{\frac{-2 \cdot b_2}{a}} \]
      2. associate-*l/49.2%

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

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

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

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

Alternative 6: 42.9% accurate, 15.9× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;b_2 \leq -72000000:\\
\;\;\;\;0.5 \cdot \frac{c}{b_2}\\

\mathbf{else}:\\
\;\;\;\;\frac{-2}{\frac{a}{b_2}}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if b_2 < -7.2e7

    1. Initial program 14.3%

      \[\frac{\left(-b_2\right) - \sqrt{b_2 \cdot b_2 - a \cdot c}}{a} \]
    2. Taylor expanded in b_2 around inf 2.4%

      \[\leadsto \frac{\color{blue}{-2 \cdot b_2 + 0.5 \cdot \frac{c \cdot a}{b_2}}}{a} \]
    3. Taylor expanded in b_2 around 0 36.3%

      \[\leadsto \color{blue}{0.5 \cdot \frac{c}{b_2}} \]

    if -7.2e7 < b_2

    1. Initial program 72.5%

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

        \[\leadsto \color{blue}{e^{\log \left(\frac{\left(-b_2\right) - \sqrt{b_2 \cdot b_2 - a \cdot c}}{a}\right)}} \]
      2. add-sqr-sqrt9.5%

        \[\leadsto e^{\log \left(\frac{\color{blue}{\sqrt{-b_2} \cdot \sqrt{-b_2}} - \sqrt{b_2 \cdot b_2 - a \cdot c}}{a}\right)} \]
      3. sqrt-unprod21.9%

        \[\leadsto e^{\log \left(\frac{\color{blue}{\sqrt{\left(-b_2\right) \cdot \left(-b_2\right)}} - \sqrt{b_2 \cdot b_2 - a \cdot c}}{a}\right)} \]
      4. sqr-neg21.9%

        \[\leadsto e^{\log \left(\frac{\sqrt{\color{blue}{b_2 \cdot b_2}} - \sqrt{b_2 \cdot b_2 - a \cdot c}}{a}\right)} \]
      5. sqrt-prod17.0%

        \[\leadsto e^{\log \left(\frac{\color{blue}{\sqrt{b_2} \cdot \sqrt{b_2}} - \sqrt{b_2 \cdot b_2 - a \cdot c}}{a}\right)} \]
      6. add-sqr-sqrt25.9%

        \[\leadsto e^{\log \left(\frac{\color{blue}{b_2} - \sqrt{b_2 \cdot b_2 - a \cdot c}}{a}\right)} \]
      7. sub-neg25.9%

        \[\leadsto e^{\log \left(\frac{b_2 - \sqrt{\color{blue}{b_2 \cdot b_2 + \left(-a \cdot c\right)}}}{a}\right)} \]
      8. add-sqr-sqrt23.8%

        \[\leadsto e^{\log \left(\frac{b_2 - \sqrt{b_2 \cdot b_2 + \color{blue}{\sqrt{-a \cdot c} \cdot \sqrt{-a \cdot c}}}}{a}\right)} \]
      9. hypot-def21.7%

        \[\leadsto e^{\log \left(\frac{b_2 - \color{blue}{\mathsf{hypot}\left(b_2, \sqrt{-a \cdot c}\right)}}{a}\right)} \]
      10. *-commutative21.7%

        \[\leadsto e^{\log \left(\frac{b_2 - \mathsf{hypot}\left(b_2, \sqrt{-\color{blue}{c \cdot a}}\right)}{a}\right)} \]
      11. distribute-rgt-neg-in21.7%

        \[\leadsto e^{\log \left(\frac{b_2 - \mathsf{hypot}\left(b_2, \sqrt{\color{blue}{c \cdot \left(-a\right)}}\right)}{a}\right)} \]
    3. Applied egg-rr21.7%

      \[\leadsto \color{blue}{e^{\log \left(\frac{b_2 - \mathsf{hypot}\left(b_2, \sqrt{c \cdot \left(-a\right)}\right)}{a}\right)}} \]
    4. Taylor expanded in b_2 around -inf 2.5%

      \[\leadsto \color{blue}{2 \cdot \frac{b_2}{a}} \]
    5. Step-by-step derivation
      1. add-sqr-sqrt1.6%

        \[\leadsto \color{blue}{\sqrt{2 \cdot \frac{b_2}{a}} \cdot \sqrt{2 \cdot \frac{b_2}{a}}} \]
      2. sqrt-unprod21.5%

        \[\leadsto \color{blue}{\sqrt{\left(2 \cdot \frac{b_2}{a}\right) \cdot \left(2 \cdot \frac{b_2}{a}\right)}} \]
      3. swap-sqr21.5%

        \[\leadsto \sqrt{\color{blue}{\left(2 \cdot 2\right) \cdot \left(\frac{b_2}{a} \cdot \frac{b_2}{a}\right)}} \]
      4. metadata-eval21.5%

        \[\leadsto \sqrt{\color{blue}{4} \cdot \left(\frac{b_2}{a} \cdot \frac{b_2}{a}\right)} \]
      5. metadata-eval21.5%

        \[\leadsto \sqrt{\color{blue}{\left(-2 \cdot -2\right)} \cdot \left(\frac{b_2}{a} \cdot \frac{b_2}{a}\right)} \]
      6. swap-sqr21.5%

        \[\leadsto \sqrt{\color{blue}{\left(-2 \cdot \frac{b_2}{a}\right) \cdot \left(-2 \cdot \frac{b_2}{a}\right)}} \]
      7. sqrt-unprod27.4%

        \[\leadsto \color{blue}{\sqrt{-2 \cdot \frac{b_2}{a}} \cdot \sqrt{-2 \cdot \frac{b_2}{a}}} \]
      8. add-sqr-sqrt49.3%

        \[\leadsto \color{blue}{-2 \cdot \frac{b_2}{a}} \]
      9. clear-num49.2%

        \[\leadsto -2 \cdot \color{blue}{\frac{1}{\frac{a}{b_2}}} \]
      10. un-div-inv49.2%

        \[\leadsto \color{blue}{\frac{-2}{\frac{a}{b_2}}} \]
    6. Applied egg-rr49.2%

      \[\leadsto \color{blue}{\frac{-2}{\frac{a}{b_2}}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification45.3%

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

Alternative 7: 67.9% accurate, 15.9× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;b_2 \leq -2.8 \cdot 10^{-275}:\\
\;\;\;\;\frac{-0.5 \cdot c}{b_2}\\

\mathbf{else}:\\
\;\;\;\;\frac{-2}{\frac{a}{b_2}}\\


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

    1. Initial program 31.7%

      \[\frac{\left(-b_2\right) - \sqrt{b_2 \cdot b_2 - a \cdot c}}{a} \]
    2. Taylor expanded in b_2 around -inf 69.2%

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

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

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

    if -2.79999999999999994e-275 < b_2

    1. Initial program 76.1%

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

        \[\leadsto \color{blue}{e^{\log \left(\frac{\left(-b_2\right) - \sqrt{b_2 \cdot b_2 - a \cdot c}}{a}\right)}} \]
      2. add-sqr-sqrt2.1%

        \[\leadsto e^{\log \left(\frac{\color{blue}{\sqrt{-b_2} \cdot \sqrt{-b_2}} - \sqrt{b_2 \cdot b_2 - a \cdot c}}{a}\right)} \]
      3. sqrt-unprod18.6%

        \[\leadsto e^{\log \left(\frac{\color{blue}{\sqrt{\left(-b_2\right) \cdot \left(-b_2\right)}} - \sqrt{b_2 \cdot b_2 - a \cdot c}}{a}\right)} \]
      4. sqr-neg18.6%

        \[\leadsto e^{\log \left(\frac{\sqrt{\color{blue}{b_2 \cdot b_2}} - \sqrt{b_2 \cdot b_2 - a \cdot c}}{a}\right)} \]
      5. sqrt-prod22.7%

        \[\leadsto e^{\log \left(\frac{\color{blue}{\sqrt{b_2} \cdot \sqrt{b_2}} - \sqrt{b_2 \cdot b_2 - a \cdot c}}{a}\right)} \]
      6. add-sqr-sqrt24.0%

        \[\leadsto e^{\log \left(\frac{\color{blue}{b_2} - \sqrt{b_2 \cdot b_2 - a \cdot c}}{a}\right)} \]
      7. sub-neg24.0%

        \[\leadsto e^{\log \left(\frac{b_2 - \sqrt{\color{blue}{b_2 \cdot b_2 + \left(-a \cdot c\right)}}}{a}\right)} \]
      8. add-sqr-sqrt21.2%

        \[\leadsto e^{\log \left(\frac{b_2 - \sqrt{b_2 \cdot b_2 + \color{blue}{\sqrt{-a \cdot c} \cdot \sqrt{-a \cdot c}}}}{a}\right)} \]
      9. hypot-def18.5%

        \[\leadsto e^{\log \left(\frac{b_2 - \color{blue}{\mathsf{hypot}\left(b_2, \sqrt{-a \cdot c}\right)}}{a}\right)} \]
      10. *-commutative18.5%

        \[\leadsto e^{\log \left(\frac{b_2 - \mathsf{hypot}\left(b_2, \sqrt{-\color{blue}{c \cdot a}}\right)}{a}\right)} \]
      11. distribute-rgt-neg-in18.5%

        \[\leadsto e^{\log \left(\frac{b_2 - \mathsf{hypot}\left(b_2, \sqrt{\color{blue}{c \cdot \left(-a\right)}}\right)}{a}\right)} \]
    3. Applied egg-rr18.5%

      \[\leadsto \color{blue}{e^{\log \left(\frac{b_2 - \mathsf{hypot}\left(b_2, \sqrt{c \cdot \left(-a\right)}\right)}{a}\right)}} \]
    4. Taylor expanded in b_2 around -inf 1.8%

      \[\leadsto \color{blue}{2 \cdot \frac{b_2}{a}} \]
    5. Step-by-step derivation
      1. add-sqr-sqrt1.0%

        \[\leadsto \color{blue}{\sqrt{2 \cdot \frac{b_2}{a}} \cdot \sqrt{2 \cdot \frac{b_2}{a}}} \]
      2. sqrt-unprod27.4%

        \[\leadsto \color{blue}{\sqrt{\left(2 \cdot \frac{b_2}{a}\right) \cdot \left(2 \cdot \frac{b_2}{a}\right)}} \]
      3. swap-sqr27.4%

        \[\leadsto \sqrt{\color{blue}{\left(2 \cdot 2\right) \cdot \left(\frac{b_2}{a} \cdot \frac{b_2}{a}\right)}} \]
      4. metadata-eval27.4%

        \[\leadsto \sqrt{\color{blue}{4} \cdot \left(\frac{b_2}{a} \cdot \frac{b_2}{a}\right)} \]
      5. metadata-eval27.4%

        \[\leadsto \sqrt{\color{blue}{\left(-2 \cdot -2\right)} \cdot \left(\frac{b_2}{a} \cdot \frac{b_2}{a}\right)} \]
      6. swap-sqr27.4%

        \[\leadsto \sqrt{\color{blue}{\left(-2 \cdot \frac{b_2}{a}\right) \cdot \left(-2 \cdot \frac{b_2}{a}\right)}} \]
      7. sqrt-unprod35.9%

        \[\leadsto \color{blue}{\sqrt{-2 \cdot \frac{b_2}{a}} \cdot \sqrt{-2 \cdot \frac{b_2}{a}}} \]
      8. add-sqr-sqrt64.8%

        \[\leadsto \color{blue}{-2 \cdot \frac{b_2}{a}} \]
      9. clear-num64.6%

        \[\leadsto -2 \cdot \color{blue}{\frac{1}{\frac{a}{b_2}}} \]
      10. un-div-inv64.6%

        \[\leadsto \color{blue}{\frac{-2}{\frac{a}{b_2}}} \]
    6. Applied egg-rr64.6%

      \[\leadsto \color{blue}{\frac{-2}{\frac{a}{b_2}}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification66.9%

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

Alternative 8: 67.9% accurate, 15.9× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;b_2 \leq -2.9 \cdot 10^{-275}:\\
\;\;\;\;\frac{-0.5 \cdot c}{b_2}\\

\mathbf{else}:\\
\;\;\;\;\frac{b_2 \cdot -2}{a}\\


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

    1. Initial program 31.7%

      \[\frac{\left(-b_2\right) - \sqrt{b_2 \cdot b_2 - a \cdot c}}{a} \]
    2. Taylor expanded in b_2 around -inf 69.2%

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

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

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

    if -2.9e-275 < b_2

    1. Initial program 76.1%

      \[\frac{\left(-b_2\right) - \sqrt{b_2 \cdot b_2 - a \cdot c}}{a} \]
    2. Taylor expanded in b_2 around inf 64.8%

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

        \[\leadsto \frac{\color{blue}{b_2 \cdot -2}}{a} \]
    4. Simplified64.8%

      \[\leadsto \frac{\color{blue}{b_2 \cdot -2}}{a} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification66.9%

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

Alternative 9: 10.4% accurate, 22.4× speedup?

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

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

    \[\frac{\left(-b_2\right) - \sqrt{b_2 \cdot b_2 - a \cdot c}}{a} \]
  2. Taylor expanded in b_2 around inf 31.8%

    \[\leadsto \frac{\color{blue}{-2 \cdot b_2 + 0.5 \cdot \frac{c \cdot a}{b_2}}}{a} \]
  3. Taylor expanded in b_2 around 0 13.4%

    \[\leadsto \color{blue}{0.5 \cdot \frac{c}{b_2}} \]
  4. Final simplification13.4%

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

Reproduce

?
herbie shell --seed 2023257 
(FPCore (a b_2 c)
  :name "quad2m (problem 3.2.1, negative)"
  :precision binary64
  (/ (- (- b_2) (sqrt (- (* b_2 b_2) (* a c)))) a))