Quadratic roots, full range

Percentage Accurate: 52.0% → 84.6%
Time: 11.5s
Alternatives: 8
Speedup: 12.9×

Specification

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

\\
\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot 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 8 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.0% accurate, 1.0× speedup?

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

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

Alternative 1: 84.6% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;b \leq -1.66 \cdot 10^{+180}:\\ \;\;\;\;\frac{0.5}{a} \cdot \left(\left|\mathsf{fma}\left(a, -2 \cdot \frac{c}{b}, b\right)\right| - b\right)\\ \mathbf{elif}\;b \leq 3.4 \cdot 10^{-79}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)} - b}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;-\frac{c}{b}\\ \end{array} \end{array} \]
(FPCore (a b c)
 :precision binary64
 (if (<= b -1.66e+180)
   (* (/ 0.5 a) (- (fabs (fma a (* -2.0 (/ c b)) b)) b))
   (if (<= b 3.4e-79)
     (/ (- (sqrt (- (* b b) (* c (* a 4.0)))) b) (* a 2.0))
     (- (/ c b)))))
double code(double a, double b, double c) {
	double tmp;
	if (b <= -1.66e+180) {
		tmp = (0.5 / a) * (fabs(fma(a, (-2.0 * (c / b)), b)) - b);
	} else if (b <= 3.4e-79) {
		tmp = (sqrt(((b * b) - (c * (a * 4.0)))) - b) / (a * 2.0);
	} else {
		tmp = -(c / b);
	}
	return tmp;
}
function code(a, b, c)
	tmp = 0.0
	if (b <= -1.66e+180)
		tmp = Float64(Float64(0.5 / a) * Float64(abs(fma(a, Float64(-2.0 * Float64(c / b)), b)) - b));
	elseif (b <= 3.4e-79)
		tmp = Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(c * Float64(a * 4.0)))) - b) / Float64(a * 2.0));
	else
		tmp = Float64(-Float64(c / b));
	end
	return tmp
end
code[a_, b_, c_] := If[LessEqual[b, -1.66e+180], N[(N[(0.5 / a), $MachinePrecision] * N[(N[Abs[N[(a * N[(-2.0 * N[(c / b), $MachinePrecision]), $MachinePrecision] + b), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 3.4e-79], N[(N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(c * N[(a * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], (-N[(c / b), $MachinePrecision])]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.66 \cdot 10^{+180}:\\
\;\;\;\;\frac{0.5}{a} \cdot \left(\left|\mathsf{fma}\left(a, -2 \cdot \frac{c}{b}, b\right)\right| - b\right)\\

\mathbf{elif}\;b \leq 3.4 \cdot 10^{-79}:\\
\;\;\;\;\frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)} - b}{a \cdot 2}\\

\mathbf{else}:\\
\;\;\;\;-\frac{c}{b}\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if b < -1.6600000000000001e180

    1. Initial program 47.9%

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

        \[\leadsto \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\color{blue}{a \cdot 2}} \]
    3. Simplified47.9%

      \[\leadsto \color{blue}{\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{a \cdot 2}} \]
    4. Add Preprocessing
    5. Applied egg-rr48.0%

      \[\leadsto \color{blue}{\sqrt{\mathsf{fma}\left(a, c \cdot -4, {b}^{2}\right)} \cdot \frac{0.5}{a} + \left(-b \cdot \frac{0.5}{a}\right)} \]
    6. Step-by-step derivation
      1. sub-neg48.0%

        \[\leadsto \color{blue}{\sqrt{\mathsf{fma}\left(a, c \cdot -4, {b}^{2}\right)} \cdot \frac{0.5}{a} - b \cdot \frac{0.5}{a}} \]
      2. distribute-rgt-out--48.0%

        \[\leadsto \color{blue}{\frac{0.5}{a} \cdot \left(\sqrt{\mathsf{fma}\left(a, c \cdot -4, {b}^{2}\right)} - b\right)} \]
    7. Simplified48.0%

      \[\leadsto \color{blue}{\frac{0.5}{a} \cdot \left(\sqrt{\mathsf{fma}\left(a, c \cdot -4, {b}^{2}\right)} - b\right)} \]
    8. Taylor expanded in a around 0 2.0%

      \[\leadsto \frac{0.5}{a} \cdot \left(\color{blue}{\left(b + -2 \cdot \frac{a \cdot c}{b}\right)} - b\right) \]
    9. Step-by-step derivation
      1. associate-*r/2.0%

        \[\leadsto \frac{0.5}{a} \cdot \left(\left(b + \color{blue}{\frac{-2 \cdot \left(a \cdot c\right)}{b}}\right) - b\right) \]
      2. associate-*r*2.0%

        \[\leadsto \frac{0.5}{a} \cdot \left(\left(b + \frac{\color{blue}{\left(-2 \cdot a\right) \cdot c}}{b}\right) - b\right) \]
      3. *-commutative2.0%

        \[\leadsto \frac{0.5}{a} \cdot \left(\left(b + \frac{\color{blue}{\left(a \cdot -2\right)} \cdot c}{b}\right) - b\right) \]
      4. associate-*l*2.0%

        \[\leadsto \frac{0.5}{a} \cdot \left(\left(b + \frac{\color{blue}{a \cdot \left(-2 \cdot c\right)}}{b}\right) - b\right) \]
    10. Simplified2.0%

      \[\leadsto \frac{0.5}{a} \cdot \left(\color{blue}{\left(b + \frac{a \cdot \left(-2 \cdot c\right)}{b}\right)} - b\right) \]
    11. Step-by-step derivation
      1. add-sqr-sqrt0.2%

        \[\leadsto \frac{0.5}{a} \cdot \left(\color{blue}{\sqrt{b + \frac{a \cdot \left(-2 \cdot c\right)}{b}} \cdot \sqrt{b + \frac{a \cdot \left(-2 \cdot c\right)}{b}}} - b\right) \]
      2. sqrt-unprod48.0%

        \[\leadsto \frac{0.5}{a} \cdot \left(\color{blue}{\sqrt{\left(b + \frac{a \cdot \left(-2 \cdot c\right)}{b}\right) \cdot \left(b + \frac{a \cdot \left(-2 \cdot c\right)}{b}\right)}} - b\right) \]
      3. pow248.0%

        \[\leadsto \frac{0.5}{a} \cdot \left(\sqrt{\color{blue}{{\left(b + \frac{a \cdot \left(-2 \cdot c\right)}{b}\right)}^{2}}} - b\right) \]
      4. +-commutative48.0%

        \[\leadsto \frac{0.5}{a} \cdot \left(\sqrt{{\color{blue}{\left(\frac{a \cdot \left(-2 \cdot c\right)}{b} + b\right)}}^{2}} - b\right) \]
      5. associate-/l*48.0%

        \[\leadsto \frac{0.5}{a} \cdot \left(\sqrt{{\left(\color{blue}{a \cdot \frac{-2 \cdot c}{b}} + b\right)}^{2}} - b\right) \]
      6. fma-define48.0%

        \[\leadsto \frac{0.5}{a} \cdot \left(\sqrt{{\color{blue}{\left(\mathsf{fma}\left(a, \frac{-2 \cdot c}{b}, b\right)\right)}}^{2}} - b\right) \]
      7. *-commutative48.0%

        \[\leadsto \frac{0.5}{a} \cdot \left(\sqrt{{\left(\mathsf{fma}\left(a, \frac{\color{blue}{c \cdot -2}}{b}, b\right)\right)}^{2}} - b\right) \]
    12. Applied egg-rr48.0%

      \[\leadsto \frac{0.5}{a} \cdot \left(\color{blue}{\sqrt{{\left(\mathsf{fma}\left(a, \frac{c \cdot -2}{b}, b\right)\right)}^{2}}} - b\right) \]
    13. Step-by-step derivation
      1. unpow248.0%

        \[\leadsto \frac{0.5}{a} \cdot \left(\sqrt{\color{blue}{\mathsf{fma}\left(a, \frac{c \cdot -2}{b}, b\right) \cdot \mathsf{fma}\left(a, \frac{c \cdot -2}{b}, b\right)}} - b\right) \]
      2. rem-sqrt-square97.7%

        \[\leadsto \frac{0.5}{a} \cdot \left(\color{blue}{\left|\mathsf{fma}\left(a, \frac{c \cdot -2}{b}, b\right)\right|} - b\right) \]
      3. *-commutative97.7%

        \[\leadsto \frac{0.5}{a} \cdot \left(\left|\mathsf{fma}\left(a, \frac{\color{blue}{-2 \cdot c}}{b}, b\right)\right| - b\right) \]
      4. associate-*r/97.7%

        \[\leadsto \frac{0.5}{a} \cdot \left(\left|\mathsf{fma}\left(a, \color{blue}{-2 \cdot \frac{c}{b}}, b\right)\right| - b\right) \]
    14. Simplified97.7%

      \[\leadsto \frac{0.5}{a} \cdot \left(\color{blue}{\left|\mathsf{fma}\left(a, -2 \cdot \frac{c}{b}, b\right)\right|} - b\right) \]

    if -1.6600000000000001e180 < b < 3.39999999999999976e-79

    1. Initial program 85.0%

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a} \]
    2. Add Preprocessing

    if 3.39999999999999976e-79 < b

    1. Initial program 18.6%

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

        \[\leadsto \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\color{blue}{a \cdot 2}} \]
    3. Simplified18.6%

      \[\leadsto \color{blue}{\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{a \cdot 2}} \]
    4. Add Preprocessing
    5. Taylor expanded in b around inf 86.4%

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

        \[\leadsto \color{blue}{\frac{-1 \cdot c}{b}} \]
      2. mul-1-neg86.4%

        \[\leadsto \frac{\color{blue}{-c}}{b} \]
    7. Simplified86.4%

      \[\leadsto \color{blue}{\frac{-c}{b}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification87.6%

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -1.66 \cdot 10^{+180}:\\ \;\;\;\;\frac{0.5}{a} \cdot \left(\left|\mathsf{fma}\left(a, -2 \cdot \frac{c}{b}, b\right)\right| - b\right)\\ \mathbf{elif}\;b \leq 3.4 \cdot 10^{-79}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)} - b}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;-\frac{c}{b}\\ \end{array} \]
  5. Add Preprocessing

Alternative 2: 85.9% accurate, 0.9× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;b \leq -7.2 \cdot 10^{+63}:\\
\;\;\;\;\frac{b}{-a}\\

\mathbf{elif}\;b \leq 1.1 \cdot 10^{-78}:\\
\;\;\;\;\frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)} - b}{a \cdot 2}\\

\mathbf{else}:\\
\;\;\;\;-\frac{c}{b}\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if b < -7.19999999999999998e63

    1. Initial program 64.8%

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

        \[\leadsto \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\color{blue}{a \cdot 2}} \]
    3. Simplified64.8%

      \[\leadsto \color{blue}{\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{a \cdot 2}} \]
    4. Add Preprocessing
    5. Taylor expanded in b around -inf 96.7%

      \[\leadsto \color{blue}{-1 \cdot \frac{b}{a}} \]
    6. Step-by-step derivation
      1. associate-*r/96.7%

        \[\leadsto \color{blue}{\frac{-1 \cdot b}{a}} \]
      2. mul-1-neg96.7%

        \[\leadsto \frac{\color{blue}{-b}}{a} \]
    7. Simplified96.7%

      \[\leadsto \color{blue}{\frac{-b}{a}} \]

    if -7.19999999999999998e63 < b < 1.0999999999999999e-78

    1. Initial program 82.4%

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a} \]
    2. Add Preprocessing

    if 1.0999999999999999e-78 < b

    1. Initial program 18.6%

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

        \[\leadsto \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\color{blue}{a \cdot 2}} \]
    3. Simplified18.6%

      \[\leadsto \color{blue}{\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{a \cdot 2}} \]
    4. Add Preprocessing
    5. Taylor expanded in b around inf 86.4%

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

        \[\leadsto \color{blue}{\frac{-1 \cdot c}{b}} \]
      2. mul-1-neg86.4%

        \[\leadsto \frac{\color{blue}{-c}}{b} \]
    7. Simplified86.4%

      \[\leadsto \color{blue}{\frac{-c}{b}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification87.5%

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -7.2 \cdot 10^{+63}:\\ \;\;\;\;\frac{b}{-a}\\ \mathbf{elif}\;b \leq 1.1 \cdot 10^{-78}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)} - b}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;-\frac{c}{b}\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 80.5% accurate, 1.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.55 \cdot 10^{-27}:\\
\;\;\;\;\frac{b}{-a}\\

\mathbf{elif}\;b \leq 2.6 \cdot 10^{-84}:\\
\;\;\;\;\frac{\sqrt{a \cdot \left(c \cdot -4\right)} - b}{a \cdot 2}\\

\mathbf{else}:\\
\;\;\;\;-\frac{c}{b}\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if b < -1.5499999999999999e-27

    1. Initial program 72.8%

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

        \[\leadsto \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\color{blue}{a \cdot 2}} \]
    3. Simplified72.8%

      \[\leadsto \color{blue}{\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{a \cdot 2}} \]
    4. Add Preprocessing
    5. Taylor expanded in b around -inf 95.4%

      \[\leadsto \color{blue}{-1 \cdot \frac{b}{a}} \]
    6. Step-by-step derivation
      1. associate-*r/95.4%

        \[\leadsto \color{blue}{\frac{-1 \cdot b}{a}} \]
      2. mul-1-neg95.4%

        \[\leadsto \frac{\color{blue}{-b}}{a} \]
    7. Simplified95.4%

      \[\leadsto \color{blue}{\frac{-b}{a}} \]

    if -1.5499999999999999e-27 < b < 2.6e-84

    1. Initial program 78.0%

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

        \[\leadsto \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\color{blue}{a \cdot 2}} \]
    3. Simplified78.0%

      \[\leadsto \color{blue}{\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{a \cdot 2}} \]
    4. Add Preprocessing
    5. Taylor expanded in b around 0 68.6%

      \[\leadsto \frac{\left(-b\right) + \sqrt{\color{blue}{-4 \cdot \left(a \cdot c\right)}}}{a \cdot 2} \]
    6. Step-by-step derivation
      1. *-commutative68.6%

        \[\leadsto \frac{\left(-b\right) + \sqrt{\color{blue}{\left(a \cdot c\right) \cdot -4}}}{a \cdot 2} \]
      2. associate-*r*68.6%

        \[\leadsto \frac{\left(-b\right) + \sqrt{\color{blue}{a \cdot \left(c \cdot -4\right)}}}{a \cdot 2} \]
    7. Simplified68.6%

      \[\leadsto \frac{\left(-b\right) + \sqrt{\color{blue}{a \cdot \left(c \cdot -4\right)}}}{a \cdot 2} \]

    if 2.6e-84 < b

    1. Initial program 19.2%

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

        \[\leadsto \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\color{blue}{a \cdot 2}} \]
    3. Simplified19.2%

      \[\leadsto \color{blue}{\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{a \cdot 2}} \]
    4. Add Preprocessing
    5. Taylor expanded in b around inf 86.0%

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

        \[\leadsto \color{blue}{\frac{-1 \cdot c}{b}} \]
      2. mul-1-neg86.0%

        \[\leadsto \frac{\color{blue}{-c}}{b} \]
    7. Simplified86.0%

      \[\leadsto \color{blue}{\frac{-c}{b}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification83.9%

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -1.55 \cdot 10^{-27}:\\ \;\;\;\;\frac{b}{-a}\\ \mathbf{elif}\;b \leq 2.6 \cdot 10^{-84}:\\ \;\;\;\;\frac{\sqrt{a \cdot \left(c \cdot -4\right)} - b}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;-\frac{c}{b}\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 72.7% accurate, 1.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;b \leq -8.2 \cdot 10^{-159}:\\
\;\;\;\;\frac{b}{-a}\\

\mathbf{elif}\;b \leq 5.3 \cdot 10^{-90}:\\
\;\;\;\;-0.5 \cdot \left(-\sqrt{c \cdot \frac{-4}{a}}\right)\\

\mathbf{else}:\\
\;\;\;\;-\frac{c}{b}\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if b < -8.20000000000000029e-159

    1. Initial program 76.7%

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

        \[\leadsto \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\color{blue}{a \cdot 2}} \]
    3. Simplified76.7%

      \[\leadsto \color{blue}{\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{a \cdot 2}} \]
    4. Add Preprocessing
    5. Taylor expanded in b around -inf 79.5%

      \[\leadsto \color{blue}{-1 \cdot \frac{b}{a}} \]
    6. Step-by-step derivation
      1. associate-*r/79.5%

        \[\leadsto \color{blue}{\frac{-1 \cdot b}{a}} \]
      2. mul-1-neg79.5%

        \[\leadsto \frac{\color{blue}{-b}}{a} \]
    7. Simplified79.5%

      \[\leadsto \color{blue}{\frac{-b}{a}} \]

    if -8.20000000000000029e-159 < b < 5.3000000000000004e-90

    1. Initial program 72.0%

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

        \[\leadsto \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\color{blue}{a \cdot 2}} \]
    3. Simplified72.0%

      \[\leadsto \color{blue}{\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{a \cdot 2}} \]
    4. Add Preprocessing
    5. Step-by-step derivation
      1. add-cube-cbrt71.6%

        \[\leadsto \frac{\left(-b\right) + \sqrt{b \cdot b - \color{blue}{\left(\left(\sqrt[3]{4 \cdot a} \cdot \sqrt[3]{4 \cdot a}\right) \cdot \sqrt[3]{4 \cdot a}\right)} \cdot c}}{a \cdot 2} \]
      2. pow371.6%

        \[\leadsto \frac{\left(-b\right) + \sqrt{b \cdot b - \color{blue}{{\left(\sqrt[3]{4 \cdot a}\right)}^{3}} \cdot c}}{a \cdot 2} \]
    6. Applied egg-rr71.6%

      \[\leadsto \frac{\left(-b\right) + \sqrt{b \cdot b - \color{blue}{{\left(\sqrt[3]{4 \cdot a}\right)}^{3}} \cdot c}}{a \cdot 2} \]
    7. Taylor expanded in a around -inf 0.0%

      \[\leadsto \color{blue}{-0.5 \cdot \left(\sqrt{\frac{c \cdot {\left(\sqrt[3]{-4}\right)}^{3}}{a}} \cdot {\left(\sqrt{-1}\right)}^{2}\right)} \]
    8. Step-by-step derivation
      1. *-commutative0.0%

        \[\leadsto -0.5 \cdot \color{blue}{\left({\left(\sqrt{-1}\right)}^{2} \cdot \sqrt{\frac{c \cdot {\left(\sqrt[3]{-4}\right)}^{3}}{a}}\right)} \]
      2. unpow20.0%

        \[\leadsto -0.5 \cdot \left(\color{blue}{\left(\sqrt{-1} \cdot \sqrt{-1}\right)} \cdot \sqrt{\frac{c \cdot {\left(\sqrt[3]{-4}\right)}^{3}}{a}}\right) \]
      3. rem-square-sqrt43.4%

        \[\leadsto -0.5 \cdot \left(\color{blue}{-1} \cdot \sqrt{\frac{c \cdot {\left(\sqrt[3]{-4}\right)}^{3}}{a}}\right) \]
      4. associate-/l*43.3%

        \[\leadsto -0.5 \cdot \left(-1 \cdot \sqrt{\color{blue}{c \cdot \frac{{\left(\sqrt[3]{-4}\right)}^{3}}{a}}}\right) \]
      5. rem-cube-cbrt43.8%

        \[\leadsto -0.5 \cdot \left(-1 \cdot \sqrt{c \cdot \frac{\color{blue}{-4}}{a}}\right) \]
    9. Simplified43.8%

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

    if 5.3000000000000004e-90 < b

    1. Initial program 19.2%

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

        \[\leadsto \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\color{blue}{a \cdot 2}} \]
    3. Simplified19.2%

      \[\leadsto \color{blue}{\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{a \cdot 2}} \]
    4. Add Preprocessing
    5. Taylor expanded in b around inf 86.0%

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

        \[\leadsto \color{blue}{\frac{-1 \cdot c}{b}} \]
      2. mul-1-neg86.0%

        \[\leadsto \frac{\color{blue}{-c}}{b} \]
    7. Simplified86.0%

      \[\leadsto \color{blue}{\frac{-c}{b}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification75.1%

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -8.2 \cdot 10^{-159}:\\ \;\;\;\;\frac{b}{-a}\\ \mathbf{elif}\;b \leq 5.3 \cdot 10^{-90}:\\ \;\;\;\;-0.5 \cdot \left(-\sqrt{c \cdot \frac{-4}{a}}\right)\\ \mathbf{else}:\\ \;\;\;\;-\frac{c}{b}\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 69.1% accurate, 12.9× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;b \leq 3.5 \cdot 10^{-302}:\\
\;\;\;\;\frac{b}{-a}\\

\mathbf{else}:\\
\;\;\;\;-\frac{c}{b}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if b < 3.5000000000000001e-302

    1. Initial program 76.5%

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

        \[\leadsto \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\color{blue}{a \cdot 2}} \]
    3. Simplified76.5%

      \[\leadsto \color{blue}{\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{a \cdot 2}} \]
    4. Add Preprocessing
    5. Taylor expanded in b around -inf 68.1%

      \[\leadsto \color{blue}{-1 \cdot \frac{b}{a}} \]
    6. Step-by-step derivation
      1. associate-*r/68.1%

        \[\leadsto \color{blue}{\frac{-1 \cdot b}{a}} \]
      2. mul-1-neg68.1%

        \[\leadsto \frac{\color{blue}{-b}}{a} \]
    7. Simplified68.1%

      \[\leadsto \color{blue}{\frac{-b}{a}} \]

    if 3.5000000000000001e-302 < b

    1. Initial program 30.9%

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

        \[\leadsto \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\color{blue}{a \cdot 2}} \]
    3. Simplified30.9%

      \[\leadsto \color{blue}{\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{a \cdot 2}} \]
    4. Add Preprocessing
    5. Taylor expanded in b around inf 68.8%

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

        \[\leadsto \color{blue}{\frac{-1 \cdot c}{b}} \]
      2. mul-1-neg68.8%

        \[\leadsto \frac{\color{blue}{-c}}{b} \]
    7. Simplified68.8%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq 3.5 \cdot 10^{-302}:\\ \;\;\;\;\frac{b}{-a}\\ \mathbf{else}:\\ \;\;\;\;-\frac{c}{b}\\ \end{array} \]
  5. Add Preprocessing

Alternative 6: 44.5% accurate, 12.9× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;b \leq 8 \cdot 10^{+26}:\\
\;\;\;\;\frac{b}{-a}\\

\mathbf{else}:\\
\;\;\;\;\frac{c}{b}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if b < 8.00000000000000038e26

    1. Initial program 71.4%

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

        \[\leadsto \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\color{blue}{a \cdot 2}} \]
    3. Simplified71.4%

      \[\leadsto \color{blue}{\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{a \cdot 2}} \]
    4. Add Preprocessing
    5. Taylor expanded in b around -inf 49.4%

      \[\leadsto \color{blue}{-1 \cdot \frac{b}{a}} \]
    6. Step-by-step derivation
      1. associate-*r/49.4%

        \[\leadsto \color{blue}{\frac{-1 \cdot b}{a}} \]
      2. mul-1-neg49.4%

        \[\leadsto \frac{\color{blue}{-b}}{a} \]
    7. Simplified49.4%

      \[\leadsto \color{blue}{\frac{-b}{a}} \]

    if 8.00000000000000038e26 < b

    1. Initial program 11.2%

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

        \[\leadsto \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\color{blue}{a \cdot 2}} \]
    3. Simplified11.2%

      \[\leadsto \color{blue}{\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{a \cdot 2}} \]
    4. Add Preprocessing
    5. Taylor expanded in b around inf 95.1%

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

        \[\leadsto \color{blue}{\frac{-1 \cdot c}{b}} \]
      2. mul-1-neg95.1%

        \[\leadsto \frac{\color{blue}{-c}}{b} \]
    7. Simplified95.1%

      \[\leadsto \color{blue}{\frac{-c}{b}} \]
    8. Step-by-step derivation
      1. add-sqr-sqrt39.8%

        \[\leadsto \frac{\color{blue}{\sqrt{-c} \cdot \sqrt{-c}}}{b} \]
      2. sqrt-unprod48.1%

        \[\leadsto \frac{\color{blue}{\sqrt{\left(-c\right) \cdot \left(-c\right)}}}{b} \]
      3. sqr-neg48.1%

        \[\leadsto \frac{\sqrt{\color{blue}{c \cdot c}}}{b} \]
      4. sqrt-unprod17.8%

        \[\leadsto \frac{\color{blue}{\sqrt{c} \cdot \sqrt{c}}}{b} \]
      5. add-sqr-sqrt33.0%

        \[\leadsto \frac{\color{blue}{c}}{b} \]
      6. div-inv33.0%

        \[\leadsto \color{blue}{c \cdot \frac{1}{b}} \]
    9. Applied egg-rr33.0%

      \[\leadsto \color{blue}{c \cdot \frac{1}{b}} \]
    10. Step-by-step derivation
      1. associate-*r/33.0%

        \[\leadsto \color{blue}{\frac{c \cdot 1}{b}} \]
      2. *-rgt-identity33.0%

        \[\leadsto \frac{\color{blue}{c}}{b} \]
    11. Simplified33.0%

      \[\leadsto \color{blue}{\frac{c}{b}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification44.7%

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq 8 \cdot 10^{+26}:\\ \;\;\;\;\frac{b}{-a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b}\\ \end{array} \]
  5. Add Preprocessing

Alternative 7: 11.0% accurate, 38.7× speedup?

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

\\
\frac{c}{b}
\end{array}
Derivation
  1. Initial program 54.2%

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

      \[\leadsto \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\color{blue}{a \cdot 2}} \]
  3. Simplified54.2%

    \[\leadsto \color{blue}{\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{a \cdot 2}} \]
  4. Add Preprocessing
  5. Taylor expanded in b around inf 34.7%

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

      \[\leadsto \color{blue}{\frac{-1 \cdot c}{b}} \]
    2. mul-1-neg34.7%

      \[\leadsto \frac{\color{blue}{-c}}{b} \]
  7. Simplified34.7%

    \[\leadsto \color{blue}{\frac{-c}{b}} \]
  8. Step-by-step derivation
    1. add-sqr-sqrt14.4%

      \[\leadsto \frac{\color{blue}{\sqrt{-c} \cdot \sqrt{-c}}}{b} \]
    2. sqrt-unprod18.9%

      \[\leadsto \frac{\color{blue}{\sqrt{\left(-c\right) \cdot \left(-c\right)}}}{b} \]
    3. sqr-neg18.9%

      \[\leadsto \frac{\sqrt{\color{blue}{c \cdot c}}}{b} \]
    4. sqrt-unprod6.1%

      \[\leadsto \frac{\color{blue}{\sqrt{c} \cdot \sqrt{c}}}{b} \]
    5. add-sqr-sqrt11.6%

      \[\leadsto \frac{\color{blue}{c}}{b} \]
    6. div-inv11.6%

      \[\leadsto \color{blue}{c \cdot \frac{1}{b}} \]
  9. Applied egg-rr11.6%

    \[\leadsto \color{blue}{c \cdot \frac{1}{b}} \]
  10. Step-by-step derivation
    1. associate-*r/11.6%

      \[\leadsto \color{blue}{\frac{c \cdot 1}{b}} \]
    2. *-rgt-identity11.6%

      \[\leadsto \frac{\color{blue}{c}}{b} \]
  11. Simplified11.6%

    \[\leadsto \color{blue}{\frac{c}{b}} \]
  12. Add Preprocessing

Alternative 8: 2.5% accurate, 38.7× speedup?

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

\\
\frac{b}{a}
\end{array}
Derivation
  1. Initial program 54.2%

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

      \[\leadsto \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\color{blue}{a \cdot 2}} \]
  3. Simplified54.2%

    \[\leadsto \color{blue}{\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{a \cdot 2}} \]
  4. Add Preprocessing
  5. Taylor expanded in b around -inf 36.2%

    \[\leadsto \color{blue}{-1 \cdot \frac{b}{a}} \]
  6. Step-by-step derivation
    1. associate-*r/36.2%

      \[\leadsto \color{blue}{\frac{-1 \cdot b}{a}} \]
    2. mul-1-neg36.2%

      \[\leadsto \frac{\color{blue}{-b}}{a} \]
  7. Simplified36.2%

    \[\leadsto \color{blue}{\frac{-b}{a}} \]
  8. Step-by-step derivation
    1. div-inv36.1%

      \[\leadsto \color{blue}{\left(-b\right) \cdot \frac{1}{a}} \]
    2. add-sqr-sqrt34.6%

      \[\leadsto \color{blue}{\left(\sqrt{-b} \cdot \sqrt{-b}\right)} \cdot \frac{1}{a} \]
    3. sqrt-unprod28.2%

      \[\leadsto \color{blue}{\sqrt{\left(-b\right) \cdot \left(-b\right)}} \cdot \frac{1}{a} \]
    4. sqr-neg28.2%

      \[\leadsto \sqrt{\color{blue}{b \cdot b}} \cdot \frac{1}{a} \]
    5. sqrt-prod1.8%

      \[\leadsto \color{blue}{\left(\sqrt{b} \cdot \sqrt{b}\right)} \cdot \frac{1}{a} \]
    6. add-sqr-sqrt2.5%

      \[\leadsto \color{blue}{b} \cdot \frac{1}{a} \]
  9. Applied egg-rr2.5%

    \[\leadsto \color{blue}{b \cdot \frac{1}{a}} \]
  10. Step-by-step derivation
    1. associate-*r/2.5%

      \[\leadsto \color{blue}{\frac{b \cdot 1}{a}} \]
    2. *-rgt-identity2.5%

      \[\leadsto \frac{\color{blue}{b}}{a} \]
  11. Simplified2.5%

    \[\leadsto \color{blue}{\frac{b}{a}} \]
  12. Add Preprocessing

Reproduce

?
herbie shell --seed 2024121 
(FPCore (a b c)
  :name "Quadratic roots, full range"
  :precision binary64
  (/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))