Quadratic roots, full range

Percentage Accurate: 52.3% → 85.1%
Time: 10.5s
Alternatives: 6
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 6 alternatives:

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

Initial Program: 52.3% 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.1% accurate, 1.0× speedup?

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

\mathbf{elif}\;b \leq 1.15 \cdot 10^{-40}:\\
\;\;\;\;\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 < -4.40000000000000021e55

    1. Initial program 63.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. *-commutative63.9%

        \[\leadsto \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\color{blue}{a \cdot 2}} \]
    3. Simplified63.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 96.0%

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

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

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

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

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

    if -4.40000000000000021e55 < b < 1.15e-40

    1. Initial program 77.9%

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

    if 1.15e-40 < b

    1. Initial program 15.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. *-commutative15.6%

        \[\leadsto \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\color{blue}{a \cdot 2}} \]
    3. Simplified15.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 90.0%

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -4.4 \cdot 10^{+55}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \leq 1.15 \cdot 10^{-40}:\\ \;\;\;\;\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: 80.8% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;b \leq -1.15 \cdot 10^{-68}:\\ \;\;\;\;\frac{-b}{a}\\ \mathbf{elif}\;b \leq 1.35 \cdot 10^{-40}:\\ \;\;\;\;\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.15e-68)
   (/ (- b) a)
   (if (<= b 1.35e-40)
     (/ (- (sqrt (* a (* c -4.0))) b) (* a 2.0))
     (/ (- c) b))))
double code(double a, double b, double c) {
	double tmp;
	if (b <= -1.15e-68) {
		tmp = -b / a;
	} else if (b <= 1.35e-40) {
		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.15d-68)) then
        tmp = -b / a
    else if (b <= 1.35d-40) 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.15e-68) {
		tmp = -b / a;
	} else if (b <= 1.35e-40) {
		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.15e-68:
		tmp = -b / a
	elif b <= 1.35e-40:
		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.15e-68)
		tmp = Float64(Float64(-b) / a);
	elseif (b <= 1.35e-40)
		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.15e-68)
		tmp = -b / a;
	elseif (b <= 1.35e-40)
		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.15e-68], N[((-b) / a), $MachinePrecision], If[LessEqual[b, 1.35e-40], 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.15 \cdot 10^{-68}:\\
\;\;\;\;\frac{-b}{a}\\

\mathbf{elif}\;b \leq 1.35 \cdot 10^{-40}:\\
\;\;\;\;\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.14999999999999998e-68

    1. Initial program 69.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. *-commutative69.8%

        \[\leadsto \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\color{blue}{a \cdot 2}} \]
    3. Simplified69.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 88.8%

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

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

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

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

    if -1.14999999999999998e-68 < b < 1.35e-40

    1. Initial program 75.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. *-commutative75.5%

        \[\leadsto \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\color{blue}{a \cdot 2}} \]
    3. Simplified75.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. prod-diff75.1%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\left(-b\right) + \sqrt{{b}^{2} + \left(a \cdot \left(c \cdot -4\right) + \color{blue}{\left(\left(-c\right) \cdot \left(4 \cdot a\right) + \left(4 \cdot a\right) \cdot c\right)}\right)}}{a \cdot 2} \]
      13. distribute-lft-neg-in75.1%

        \[\leadsto \frac{\left(-b\right) + \sqrt{{b}^{2} + \left(a \cdot \left(c \cdot -4\right) + \left(\color{blue}{\left(-c \cdot \left(4 \cdot a\right)\right)} + \left(4 \cdot a\right) \cdot c\right)\right)}}{a \cdot 2} \]
      14. distribute-rgt-neg-in75.1%

        \[\leadsto \frac{\left(-b\right) + \sqrt{{b}^{2} + \left(a \cdot \left(c \cdot -4\right) + \left(\color{blue}{c \cdot \left(-4 \cdot a\right)} + \left(4 \cdot a\right) \cdot c\right)\right)}}{a \cdot 2} \]
      15. distribute-lft-neg-in75.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 1.35e-40 < b

    1. Initial program 15.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. *-commutative15.6%

        \[\leadsto \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\color{blue}{a \cdot 2}} \]
    3. Simplified15.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 90.0%

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -1.15 \cdot 10^{-68}:\\ \;\;\;\;\frac{-b}{a}\\ \mathbf{elif}\;b \leq 1.35 \cdot 10^{-40}:\\ \;\;\;\;\frac{\sqrt{a \cdot \left(c \cdot -4\right)} - b}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\frac{-c}{b}\\ \end{array} \]

Alternative 3: 80.1% accurate, 1.0× speedup?

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

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

\mathbf{elif}\;b \leq 1.1 \cdot 10^{-40}:\\
\;\;\;\;\frac{\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 < -9.5000000000000002e-119

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

        \[\leadsto \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\color{blue}{a \cdot 2}} \]
    3. Simplified71.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 84.8%

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

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

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

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

    if -9.5000000000000002e-119 < b < 1.10000000000000004e-40

    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. Step-by-step derivation
      1. prod-diff72.4%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\left(-b\right) + \sqrt{{b}^{2} + \left(a \cdot \left(c \cdot -4\right) + \color{blue}{\left(\left(-c\right) \cdot \left(4 \cdot a\right) + \left(4 \cdot a\right) \cdot c\right)}\right)}}{a \cdot 2} \]
      13. distribute-lft-neg-in72.4%

        \[\leadsto \frac{\left(-b\right) + \sqrt{{b}^{2} + \left(a \cdot \left(c \cdot -4\right) + \left(\color{blue}{\left(-c \cdot \left(4 \cdot a\right)\right)} + \left(4 \cdot a\right) \cdot c\right)\right)}}{a \cdot 2} \]
      14. distribute-rgt-neg-in72.4%

        \[\leadsto \frac{\left(-b\right) + \sqrt{{b}^{2} + \left(a \cdot \left(c \cdot -4\right) + \left(\color{blue}{c \cdot \left(-4 \cdot a\right)} + \left(4 \cdot a\right) \cdot c\right)\right)}}{a \cdot 2} \]
      15. distribute-lft-neg-in72.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{\color{blue}{\sqrt{-8 \cdot \left(a \cdot c\right) + 4 \cdot \left(a \cdot c\right)}}}{a \cdot 2} \]
    11. Step-by-step derivation
      1. distribute-rgt-out68.0%

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

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

        \[\leadsto \frac{\sqrt{\color{blue}{a \cdot \left(c \cdot -4\right)}}}{a \cdot 2} \]
    12. Simplified68.0%

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

    if 1.10000000000000004e-40 < b

    1. Initial program 15.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. *-commutative15.6%

        \[\leadsto \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\color{blue}{a \cdot 2}} \]
    3. Simplified15.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 90.0%

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -9.5 \cdot 10^{-119}:\\ \;\;\;\;\frac{-b}{a}\\ \mathbf{elif}\;b \leq 1.1 \cdot 10^{-40}:\\ \;\;\;\;\frac{\sqrt{a \cdot \left(c \cdot -4\right)}}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\frac{-c}{b}\\ \end{array} \]

Alternative 4: 67.9% accurate, 12.8× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;b \leq -1 \cdot 10^{-309}:\\
\;\;\;\;\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 < -1.000000000000002e-309

    1. Initial program 74.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. *-commutative74.4%

        \[\leadsto \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\color{blue}{a \cdot 2}} \]
    3. Simplified74.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 71.0%

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

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

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

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

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

    if -1.000000000000002e-309 < b

    1. Initial program 29.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. *-commutative29.7%

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

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

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

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

        \[\leadsto \color{blue}{\frac{-c}{b}} \]
    6. Simplified70.1%

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

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

Alternative 5: 67.6% accurate, 19.1× speedup?

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

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

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


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

    1. Initial program 74.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. *-commutative74.6%

        \[\leadsto \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\color{blue}{a \cdot 2}} \]
    3. Simplified74.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 70.5%

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

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

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

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

    if 5.1999999999999997e-278 < b

    1. Initial program 29.1%

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

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

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

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

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

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

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

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

Alternative 6: 35.5% accurate, 29.0× 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(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.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. *-commutative54.3%

      \[\leadsto \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\color{blue}{a \cdot 2}} \]
  3. Simplified54.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 40.3%

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

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

      \[\leadsto \frac{\color{blue}{-b}}{a} \]
  6. Simplified40.3%

    \[\leadsto \color{blue}{\frac{-b}{a}} \]
  7. Final simplification40.3%

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

Reproduce

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