Quadratic roots, full range

Percentage Accurate: 51.2% → 85.5%
Time: 11.3s
Alternatives: 8
Speedup: 19.1×

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: 51.2% 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: 85.5% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;b \leq -8 \cdot 10^{+158}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \leq 1.9 \cdot 10^{-86}:\\ \;\;\;\;\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 -8e+158)
   (- (/ c b) (/ b a))
   (if (<= b 1.9e-86)
     (/ (- (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 <= -8e+158) {
		tmp = (c / b) - (b / a);
	} else if (b <= 1.9e-86) {
		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 <= (-8d+158)) then
        tmp = (c / b) - (b / a)
    else if (b <= 1.9d-86) 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 <= -8e+158) {
		tmp = (c / b) - (b / a);
	} else if (b <= 1.9e-86) {
		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 <= -8e+158:
		tmp = (c / b) - (b / a)
	elif b <= 1.9e-86:
		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 <= -8e+158)
		tmp = Float64(Float64(c / b) - Float64(b / a));
	elseif (b <= 1.9e-86)
		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 <= -8e+158)
		tmp = (c / b) - (b / a);
	elseif (b <= 1.9e-86)
		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, -8e+158], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 1.9e-86], 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 -8 \cdot 10^{+158}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\

\mathbf{elif}\;b \leq 1.9 \cdot 10^{-86}:\\
\;\;\;\;\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.99999999999999962e158

    1. Initial program 39.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. *-commutative39.4%

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

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

      \[\leadsto \color{blue}{-1 \cdot \frac{b}{a} + \frac{c}{b}} \]
    5. Step-by-step derivation
      1. +-commutative94.8%

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

        \[\leadsto \frac{c}{b} + \color{blue}{\left(-\frac{b}{a}\right)} \]
      3. unsub-neg94.8%

        \[\leadsto \color{blue}{\frac{c}{b} - \frac{b}{a}} \]
    6. Simplified94.8%

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

    if -7.99999999999999962e158 < b < 1.9e-86

    1. Initial program 78.2%

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

    if 1.9e-86 < b

    1. Initial program 17.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. *-commutative17.6%

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

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

      \[\leadsto \color{blue}{-1 \cdot \frac{c}{b}} \]
    5. Step-by-step derivation
      1. mul-1-neg86.2%

        \[\leadsto \color{blue}{-\frac{c}{b}} \]
      2. distribute-neg-frac86.2%

        \[\leadsto \color{blue}{\frac{-c}{b}} \]
    6. Simplified86.2%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -8 \cdot 10^{+158}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \leq 1.9 \cdot 10^{-86}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)} - b}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\frac{-c}{b}\\ \end{array} \]

Alternative 2: 78.8% accurate, 1.0× speedup?

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

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

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

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


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

    1. Initial program 66.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. *-commutative66.9%

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

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

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

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

        \[\leadsto \frac{\color{blue}{-b}}{a} \]
    6. Simplified90.4%

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

    if -1.18e14 < b < 6.7999999999999995e-82

    1. Initial program 70.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. *-commutative70.5%

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

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

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

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

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

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

        \[\leadsto \frac{\color{blue}{0.5}}{a} \cdot \left(\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right) \]
      6. add-sqr-sqrt47.5%

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

        \[\leadsto \frac{0.5}{a} \cdot \left(\color{blue}{\sqrt{\left(-b\right) \cdot \left(-b\right)}} + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right) \]
      8. sqr-neg69.6%

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

        \[\leadsto \frac{0.5}{a} \cdot \left(\color{blue}{\sqrt{b} \cdot \sqrt{b}} + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right) \]
      10. add-sqr-sqrt62.1%

        \[\leadsto \frac{0.5}{a} \cdot \left(\color{blue}{b} + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right) \]
      11. fma-neg62.1%

        \[\leadsto \frac{0.5}{a} \cdot \left(b + \sqrt{\color{blue}{\mathsf{fma}\left(b, b, -\left(4 \cdot a\right) \cdot c\right)}}\right) \]
      12. *-commutative62.1%

        \[\leadsto \frac{0.5}{a} \cdot \left(b + \sqrt{\mathsf{fma}\left(b, b, -\color{blue}{c \cdot \left(4 \cdot a\right)}\right)}\right) \]
      13. distribute-rgt-neg-in62.1%

        \[\leadsto \frac{0.5}{a} \cdot \left(b + \sqrt{\mathsf{fma}\left(b, b, \color{blue}{c \cdot \left(-4 \cdot a\right)}\right)}\right) \]
      14. *-commutative62.1%

        \[\leadsto \frac{0.5}{a} \cdot \left(b + \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(-\color{blue}{a \cdot 4}\right)\right)}\right) \]
      15. distribute-rgt-neg-in62.1%

        \[\leadsto \frac{0.5}{a} \cdot \left(b + \sqrt{\mathsf{fma}\left(b, b, c \cdot \color{blue}{\left(a \cdot \left(-4\right)\right)}\right)}\right) \]
      16. metadata-eval62.1%

        \[\leadsto \frac{0.5}{a} \cdot \left(b + \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot \color{blue}{-4}\right)\right)}\right) \]
    5. Applied egg-rr62.1%

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

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

    if 6.7999999999999995e-82 < b

    1. Initial program 16.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. *-commutative16.9%

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

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

      \[\leadsto \color{blue}{-1 \cdot \frac{c}{b}} \]
    5. Step-by-step derivation
      1. mul-1-neg86.9%

        \[\leadsto \color{blue}{-\frac{c}{b}} \]
      2. distribute-neg-frac86.9%

        \[\leadsto \color{blue}{\frac{-c}{b}} \]
    6. Simplified86.9%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -1.18 \cdot 10^{+14}:\\ \;\;\;\;\frac{-b}{a}\\ \mathbf{elif}\;b \leq 6.8 \cdot 10^{-82}:\\ \;\;\;\;\frac{0.5}{a} \cdot \left(b + \sqrt{-4 \cdot \left(c \cdot a\right)}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{-c}{b}\\ \end{array} \]

Alternative 3: 78.8% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;b \leq -1.18 \cdot 10^{+14}:\\ \;\;\;\;\frac{-b}{a}\\ \mathbf{elif}\;b \leq 4.5 \cdot 10^{-86}:\\ \;\;\;\;\frac{b + \sqrt{a \cdot \left(c \cdot -4\right)}}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\frac{-c}{b}\\ \end{array} \end{array} \]
(FPCore (a b c)
 :precision binary64
 (if (<= b -1.18e+14)
   (/ (- b) a)
   (if (<= b 4.5e-86)
     (/ (+ b (sqrt (* a (* c -4.0)))) (* a 2.0))
     (/ (- c) b))))
double code(double a, double b, double c) {
	double tmp;
	if (b <= -1.18e+14) {
		tmp = -b / a;
	} else if (b <= 4.5e-86) {
		tmp = (b + sqrt((a * (c * -4.0)))) / (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.18d+14)) then
        tmp = -b / a
    else if (b <= 4.5d-86) then
        tmp = (b + sqrt((a * (c * (-4.0d0))))) / (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.18e+14) {
		tmp = -b / a;
	} else if (b <= 4.5e-86) {
		tmp = (b + Math.sqrt((a * (c * -4.0)))) / (a * 2.0);
	} else {
		tmp = -c / b;
	}
	return tmp;
}
def code(a, b, c):
	tmp = 0
	if b <= -1.18e+14:
		tmp = -b / a
	elif b <= 4.5e-86:
		tmp = (b + math.sqrt((a * (c * -4.0)))) / (a * 2.0)
	else:
		tmp = -c / b
	return tmp
function code(a, b, c)
	tmp = 0.0
	if (b <= -1.18e+14)
		tmp = Float64(Float64(-b) / a);
	elseif (b <= 4.5e-86)
		tmp = Float64(Float64(b + sqrt(Float64(a * Float64(c * -4.0)))) / 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.18e+14)
		tmp = -b / a;
	elseif (b <= 4.5e-86)
		tmp = (b + sqrt((a * (c * -4.0)))) / (a * 2.0);
	else
		tmp = -c / b;
	end
	tmp_2 = tmp;
end
code[a_, b_, c_] := If[LessEqual[b, -1.18e+14], N[((-b) / a), $MachinePrecision], If[LessEqual[b, 4.5e-86], N[(N[(b + N[Sqrt[N[(a * N[(c * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], N[((-c) / b), $MachinePrecision]]]
\begin{array}{l}

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

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

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


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

    1. Initial program 66.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. *-commutative66.9%

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

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

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

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

        \[\leadsto \frac{\color{blue}{-b}}{a} \]
    6. Simplified90.4%

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

    if -1.18e14 < b < 4.4999999999999998e-86

    1. Initial program 71.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. *-commutative71.0%

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\sqrt[3]{{\left(b + \sqrt{\color{blue}{\mathsf{fma}\left(b, b, -\left(4 \cdot a\right) \cdot c\right)}}\right)}^{3}}}{a \cdot 2} \]
      9. *-commutative43.2%

        \[\leadsto \frac{\sqrt[3]{{\left(b + \sqrt{\mathsf{fma}\left(b, b, -\color{blue}{c \cdot \left(4 \cdot a\right)}\right)}\right)}^{3}}}{a \cdot 2} \]
      10. distribute-rgt-neg-in43.2%

        \[\leadsto \frac{\sqrt[3]{{\left(b + \sqrt{\mathsf{fma}\left(b, b, \color{blue}{c \cdot \left(-4 \cdot a\right)}\right)}\right)}^{3}}}{a \cdot 2} \]
      11. *-commutative43.2%

        \[\leadsto \frac{\sqrt[3]{{\left(b + \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(-\color{blue}{a \cdot 4}\right)\right)}\right)}^{3}}}{a \cdot 2} \]
      12. distribute-rgt-neg-in43.2%

        \[\leadsto \frac{\sqrt[3]{{\left(b + \sqrt{\mathsf{fma}\left(b, b, c \cdot \color{blue}{\left(a \cdot \left(-4\right)\right)}\right)}\right)}^{3}}}{a \cdot 2} \]
      13. metadata-eval43.2%

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

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

      \[\leadsto \frac{\sqrt[3]{{\left(b + \sqrt{\color{blue}{-4 \cdot \left(a \cdot c\right)}}\right)}^{3}}}{a \cdot 2} \]
    7. Step-by-step derivation
      1. rem-cbrt-cube62.3%

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

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

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

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

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

    if 4.4999999999999998e-86 < b

    1. Initial program 17.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. *-commutative17.6%

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

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

      \[\leadsto \color{blue}{-1 \cdot \frac{c}{b}} \]
    5. Step-by-step derivation
      1. mul-1-neg86.2%

        \[\leadsto \color{blue}{-\frac{c}{b}} \]
      2. distribute-neg-frac86.2%

        \[\leadsto \color{blue}{\frac{-c}{b}} \]
    6. Simplified86.2%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -1.18 \cdot 10^{+14}:\\ \;\;\;\;\frac{-b}{a}\\ \mathbf{elif}\;b \leq 4.5 \cdot 10^{-86}:\\ \;\;\;\;\frac{b + \sqrt{a \cdot \left(c \cdot -4\right)}}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\frac{-c}{b}\\ \end{array} \]

Alternative 4: 79.6% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;b \leq -1.18 \cdot 10^{+14}:\\ \;\;\;\;\frac{-b}{a}\\ \mathbf{elif}\;b \leq 4.6 \cdot 10^{-86}:\\ \;\;\;\;\frac{\sqrt{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.18e+14)
   (/ (- b) a)
   (if (<= b 4.6e-86)
     (/ (- (sqrt (* c (* a -4.0))) b) (* a 2.0))
     (/ (- c) b))))
double code(double a, double b, double c) {
	double tmp;
	if (b <= -1.18e+14) {
		tmp = -b / a;
	} else if (b <= 4.6e-86) {
		tmp = (sqrt((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 <= (-1.18d+14)) then
        tmp = -b / a
    else if (b <= 4.6d-86) then
        tmp = (sqrt((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 <= -1.18e+14) {
		tmp = -b / a;
	} else if (b <= 4.6e-86) {
		tmp = (Math.sqrt((c * (a * -4.0))) - b) / (a * 2.0);
	} else {
		tmp = -c / b;
	}
	return tmp;
}
def code(a, b, c):
	tmp = 0
	if b <= -1.18e+14:
		tmp = -b / a
	elif b <= 4.6e-86:
		tmp = (math.sqrt((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.18e+14)
		tmp = Float64(Float64(-b) / a);
	elseif (b <= 4.6e-86)
		tmp = Float64(Float64(sqrt(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 <= -1.18e+14)
		tmp = -b / a;
	elseif (b <= 4.6e-86)
		tmp = (sqrt((c * (a * -4.0))) - b) / (a * 2.0);
	else
		tmp = -c / b;
	end
	tmp_2 = tmp;
end
code[a_, b_, c_] := If[LessEqual[b, -1.18e+14], N[((-b) / a), $MachinePrecision], If[LessEqual[b, 4.6e-86], N[(N[(N[Sqrt[N[(c * N[(a * -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.18 \cdot 10^{+14}:\\
\;\;\;\;\frac{-b}{a}\\

\mathbf{elif}\;b \leq 4.6 \cdot 10^{-86}:\\
\;\;\;\;\frac{\sqrt{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.18e14

    1. Initial program 66.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. *-commutative66.9%

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

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

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

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

        \[\leadsto \frac{\color{blue}{-b}}{a} \]
    6. Simplified90.4%

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

    if -1.18e14 < b < 4.59999999999999992e-86

    1. Initial program 71.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. *-commutative71.0%

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

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

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

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

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

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

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

    if 4.59999999999999992e-86 < b

    1. Initial program 17.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. *-commutative17.6%

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

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

      \[\leadsto \color{blue}{-1 \cdot \frac{c}{b}} \]
    5. Step-by-step derivation
      1. mul-1-neg86.2%

        \[\leadsto \color{blue}{-\frac{c}{b}} \]
      2. distribute-neg-frac86.2%

        \[\leadsto \color{blue}{\frac{-c}{b}} \]
    6. Simplified86.2%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -1.18 \cdot 10^{+14}:\\ \;\;\;\;\frac{-b}{a}\\ \mathbf{elif}\;b \leq 4.6 \cdot 10^{-86}:\\ \;\;\;\;\frac{\sqrt{c \cdot \left(a \cdot -4\right)} - b}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\frac{-c}{b}\\ \end{array} \]

Alternative 5: 68.4% accurate, 12.8× speedup?

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

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

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


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

    1. Initial program 72.3%

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

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

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

      \[\leadsto \color{blue}{-1 \cdot \frac{b}{a} + \frac{c}{b}} \]
    5. Step-by-step derivation
      1. +-commutative61.6%

        \[\leadsto \color{blue}{\frac{c}{b} + -1 \cdot \frac{b}{a}} \]
      2. mul-1-neg61.6%

        \[\leadsto \frac{c}{b} + \color{blue}{\left(-\frac{b}{a}\right)} \]
      3. unsub-neg61.6%

        \[\leadsto \color{blue}{\frac{c}{b} - \frac{b}{a}} \]
    6. Simplified61.6%

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

    if -4.999999999999985e-310 < b

    1. Initial program 26.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. *-commutative26.8%

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

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

      \[\leadsto \color{blue}{-1 \cdot \frac{c}{b}} \]
    5. Step-by-step derivation
      1. mul-1-neg72.7%

        \[\leadsto \color{blue}{-\frac{c}{b}} \]
      2. distribute-neg-frac72.7%

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

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

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

Alternative 6: 43.1% accurate, 19.1× speedup?

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

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

\mathbf{else}:\\
\;\;\;\;\frac{0}{a}\\


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

    1. Initial program 71.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. *-commutative71.8%

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

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

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

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

        \[\leadsto \frac{\color{blue}{-b}}{a} \]
    6. Simplified62.5%

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

    if -9.0000000000000021e-309 < b

    1. Initial program 27.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. *-commutative27.9%

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

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

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

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

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

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

        \[\leadsto \frac{\left(-b\right) + {\left({\color{blue}{\left(\mathsf{fma}\left(b, b, -\left(4 \cdot a\right) \cdot c\right)\right)}}^{\left(\frac{0.5}{2}\right)}\right)}^{2}}{a \cdot 2} \]
      6. *-commutative25.4%

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

        \[\leadsto \frac{\left(-b\right) + {\left({\left(\mathsf{fma}\left(b, b, \color{blue}{c \cdot \left(-4 \cdot a\right)}\right)\right)}^{\left(\frac{0.5}{2}\right)}\right)}^{2}}{a \cdot 2} \]
      8. *-commutative25.4%

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

        \[\leadsto \frac{\left(-b\right) + {\left({\left(\mathsf{fma}\left(b, b, c \cdot \color{blue}{\left(a \cdot \left(-4\right)\right)}\right)\right)}^{\left(\frac{0.5}{2}\right)}\right)}^{2}}{a \cdot 2} \]
      10. metadata-eval25.4%

        \[\leadsto \frac{\left(-b\right) + {\left({\left(\mathsf{fma}\left(b, b, c \cdot \left(a \cdot \color{blue}{-4}\right)\right)\right)}^{\left(\frac{0.5}{2}\right)}\right)}^{2}}{a \cdot 2} \]
      11. metadata-eval25.4%

        \[\leadsto \frac{\left(-b\right) + {\left({\left(\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right)\right)}^{\color{blue}{0.25}}\right)}^{2}}{a \cdot 2} \]
    5. Applied egg-rr25.4%

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

        \[\leadsto \color{blue}{\left(\left(-b\right) + {\left({\left(\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right)\right)}^{0.25}\right)}^{2}\right) \cdot \frac{1}{a \cdot 2}} \]
    7. Applied egg-rr28.0%

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

      \[\leadsto \color{blue}{0.5 \cdot \frac{b + -1 \cdot b}{a}} \]
    9. Step-by-step derivation
      1. distribute-rgt1-in16.7%

        \[\leadsto 0.5 \cdot \frac{\color{blue}{\left(-1 + 1\right) \cdot b}}{a} \]
      2. metadata-eval16.7%

        \[\leadsto 0.5 \cdot \frac{\color{blue}{0} \cdot b}{a} \]
      3. mul0-lft16.7%

        \[\leadsto 0.5 \cdot \frac{\color{blue}{0}}{a} \]
      4. associate-*r/16.7%

        \[\leadsto \color{blue}{\frac{0.5 \cdot 0}{a}} \]
      5. metadata-eval16.7%

        \[\leadsto \frac{\color{blue}{0}}{a} \]
    10. Simplified16.7%

      \[\leadsto \color{blue}{\frac{0}{a}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification37.5%

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -9 \cdot 10^{-309}:\\ \;\;\;\;\frac{-b}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{0}{a}\\ \end{array} \]

Alternative 7: 68.2% accurate, 19.1× speedup?

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

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

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


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

    1. Initial program 72.3%

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

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

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

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

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

        \[\leadsto \frac{\color{blue}{-b}}{a} \]
    6. Simplified61.5%

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

    if -4.999999999999985e-310 < b

    1. Initial program 26.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. *-commutative26.8%

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

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

      \[\leadsto \color{blue}{-1 \cdot \frac{c}{b}} \]
    5. Step-by-step derivation
      1. mul-1-neg72.7%

        \[\leadsto \color{blue}{-\frac{c}{b}} \]
      2. distribute-neg-frac72.7%

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

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

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

Alternative 8: 10.9% accurate, 38.7× speedup?

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

\\
\frac{0}{a}
\end{array}
Derivation
  1. Initial program 47.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. *-commutative47.8%

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

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

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

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

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

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

      \[\leadsto \frac{\left(-b\right) + {\left({\color{blue}{\left(\mathsf{fma}\left(b, b, -\left(4 \cdot a\right) \cdot c\right)\right)}}^{\left(\frac{0.5}{2}\right)}\right)}^{2}}{a \cdot 2} \]
    6. *-commutative46.4%

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

      \[\leadsto \frac{\left(-b\right) + {\left({\left(\mathsf{fma}\left(b, b, \color{blue}{c \cdot \left(-4 \cdot a\right)}\right)\right)}^{\left(\frac{0.5}{2}\right)}\right)}^{2}}{a \cdot 2} \]
    8. *-commutative46.4%

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

      \[\leadsto \frac{\left(-b\right) + {\left({\left(\mathsf{fma}\left(b, b, c \cdot \color{blue}{\left(a \cdot \left(-4\right)\right)}\right)\right)}^{\left(\frac{0.5}{2}\right)}\right)}^{2}}{a \cdot 2} \]
    10. metadata-eval46.4%

      \[\leadsto \frac{\left(-b\right) + {\left({\left(\mathsf{fma}\left(b, b, c \cdot \left(a \cdot \color{blue}{-4}\right)\right)\right)}^{\left(\frac{0.5}{2}\right)}\right)}^{2}}{a \cdot 2} \]
    11. metadata-eval46.4%

      \[\leadsto \frac{\left(-b\right) + {\left({\left(\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right)\right)}^{\color{blue}{0.25}}\right)}^{2}}{a \cdot 2} \]
  5. Applied egg-rr46.4%

    \[\leadsto \frac{\left(-b\right) + \color{blue}{{\left({\left(\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right)\right)}^{0.25}\right)}^{2}}}{a \cdot 2} \]
  6. Step-by-step derivation
    1. div-inv46.3%

      \[\leadsto \color{blue}{\left(\left(-b\right) + {\left({\left(\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right)\right)}^{0.25}\right)}^{2}\right) \cdot \frac{1}{a \cdot 2}} \]
  7. Applied egg-rr45.1%

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

    \[\leadsto \color{blue}{0.5 \cdot \frac{b + -1 \cdot b}{a}} \]
  9. Step-by-step derivation
    1. distribute-rgt1-in10.4%

      \[\leadsto 0.5 \cdot \frac{\color{blue}{\left(-1 + 1\right) \cdot b}}{a} \]
    2. metadata-eval10.4%

      \[\leadsto 0.5 \cdot \frac{\color{blue}{0} \cdot b}{a} \]
    3. mul0-lft10.4%

      \[\leadsto 0.5 \cdot \frac{\color{blue}{0}}{a} \]
    4. associate-*r/10.4%

      \[\leadsto \color{blue}{\frac{0.5 \cdot 0}{a}} \]
    5. metadata-eval10.4%

      \[\leadsto \frac{\color{blue}{0}}{a} \]
  10. Simplified10.4%

    \[\leadsto \color{blue}{\frac{0}{a}} \]
  11. Final simplification10.4%

    \[\leadsto \frac{0}{a} \]

Reproduce

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