Quadratic roots, narrow range

Percentage Accurate: 55.2% → 92.3%
Time: 12.3s
Alternatives: 12
Speedup: 3.6×

Specification

?
\[\left(\left(1.0536712127723509 \cdot 10^{-8} < a \land a < 94906265.62425156\right) \land \left(1.0536712127723509 \cdot 10^{-8} < b \land b < 94906265.62425156\right)\right) \land \left(1.0536712127723509 \cdot 10^{-8} < c \land c < 94906265.62425156\right)\]
\[\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 12 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: 55.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: 92.3% accurate, 0.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \mathsf{fma}\left(c \cdot -4, a, b \cdot b\right)\\ \mathbf{if}\;b \leq 0.027:\\ \;\;\;\;\frac{\left(t\_0 - b \cdot b\right) \cdot \frac{0.5}{a}}{\sqrt{t\_0} + b}\\ \mathbf{else}:\\ \;\;\;\;\frac{0.5}{\mathsf{fma}\left(a, \mathsf{fma}\left(a, \left(--0.5\right) \cdot \frac{c}{\left(b \cdot b\right) \cdot b} - \frac{\left(-c\right) \cdot c}{{b}^{5}} \cdot a, \frac{0.5}{b}\right), \frac{b}{c} \cdot -0.5\right)}\\ \end{array} \end{array} \]
(FPCore (a b c)
 :precision binary64
 (let* ((t_0 (fma (* c -4.0) a (* b b))))
   (if (<= b 0.027)
     (/ (* (- t_0 (* b b)) (/ 0.5 a)) (+ (sqrt t_0) b))
     (/
      0.5
      (fma
       a
       (fma
        a
        (- (* (- -0.5) (/ c (* (* b b) b))) (* (/ (* (- c) c) (pow b 5.0)) a))
        (/ 0.5 b))
       (* (/ b c) -0.5))))))
double code(double a, double b, double c) {
	double t_0 = fma((c * -4.0), a, (b * b));
	double tmp;
	if (b <= 0.027) {
		tmp = ((t_0 - (b * b)) * (0.5 / a)) / (sqrt(t_0) + b);
	} else {
		tmp = 0.5 / fma(a, fma(a, ((-(-0.5) * (c / ((b * b) * b))) - (((-c * c) / pow(b, 5.0)) * a)), (0.5 / b)), ((b / c) * -0.5));
	}
	return tmp;
}
function code(a, b, c)
	t_0 = fma(Float64(c * -4.0), a, Float64(b * b))
	tmp = 0.0
	if (b <= 0.027)
		tmp = Float64(Float64(Float64(t_0 - Float64(b * b)) * Float64(0.5 / a)) / Float64(sqrt(t_0) + b));
	else
		tmp = Float64(0.5 / fma(a, fma(a, Float64(Float64(Float64(-(-0.5)) * Float64(c / Float64(Float64(b * b) * b))) - Float64(Float64(Float64(Float64(-c) * c) / (b ^ 5.0)) * a)), Float64(0.5 / b)), Float64(Float64(b / c) * -0.5)));
	end
	return tmp
end
code[a_, b_, c_] := Block[{t$95$0 = N[(N[(c * -4.0), $MachinePrecision] * a + N[(b * b), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[b, 0.027], N[(N[(N[(t$95$0 - N[(b * b), $MachinePrecision]), $MachinePrecision] * N[(0.5 / a), $MachinePrecision]), $MachinePrecision] / N[(N[Sqrt[t$95$0], $MachinePrecision] + b), $MachinePrecision]), $MachinePrecision], N[(0.5 / N[(a * N[(a * N[(N[((--0.5) * N[(c / N[(N[(b * b), $MachinePrecision] * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(N[(N[((-c) * c), $MachinePrecision] / N[Power[b, 5.0], $MachinePrecision]), $MachinePrecision] * a), $MachinePrecision]), $MachinePrecision] + N[(0.5 / b), $MachinePrecision]), $MachinePrecision] + N[(N[(b / c), $MachinePrecision] * -0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(c \cdot -4, a, b \cdot b\right)\\
\mathbf{if}\;b \leq 0.027:\\
\;\;\;\;\frac{\left(t\_0 - b \cdot b\right) \cdot \frac{0.5}{a}}{\sqrt{t\_0} + b}\\

\mathbf{else}:\\
\;\;\;\;\frac{0.5}{\mathsf{fma}\left(a, \mathsf{fma}\left(a, \left(--0.5\right) \cdot \frac{c}{\left(b \cdot b\right) \cdot b} - \frac{\left(-c\right) \cdot c}{{b}^{5}} \cdot a, \frac{0.5}{b}\right), \frac{b}{c} \cdot -0.5\right)}\\


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

    1. Initial program 87.1%

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. lift-/.f64N/A

        \[\leadsto \color{blue}{\frac{\left(\mathsf{neg}\left(b\right)\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}} \]
      2. div-invN/A

        \[\leadsto \color{blue}{\left(\left(\mathsf{neg}\left(b\right)\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right) \cdot \frac{1}{2 \cdot a}} \]
      3. lift-*.f64N/A

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

        \[\leadsto \left(\left(\mathsf{neg}\left(b\right)\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right) \cdot \color{blue}{\frac{\frac{1}{2}}{a}} \]
      5. metadata-evalN/A

        \[\leadsto \left(\left(\mathsf{neg}\left(b\right)\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right) \cdot \frac{\color{blue}{\frac{1}{2}}}{a} \]
      6. lift-+.f64N/A

        \[\leadsto \color{blue}{\left(\left(\mathsf{neg}\left(b\right)\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right)} \cdot \frac{\frac{1}{2}}{a} \]
      7. flip-+N/A

        \[\leadsto \color{blue}{\frac{\left(\mathsf{neg}\left(b\right)\right) \cdot \left(\mathsf{neg}\left(b\right)\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} \cdot \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\left(\mathsf{neg}\left(b\right)\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}} \cdot \frac{\frac{1}{2}}{a} \]
      8. clear-numN/A

        \[\leadsto \color{blue}{\frac{1}{\frac{\left(\mathsf{neg}\left(b\right)\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\left(\mathsf{neg}\left(b\right)\right) \cdot \left(\mathsf{neg}\left(b\right)\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} \cdot \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}} \cdot \frac{\frac{1}{2}}{a} \]
      9. frac-timesN/A

        \[\leadsto \color{blue}{\frac{1 \cdot \frac{1}{2}}{\frac{\left(\mathsf{neg}\left(b\right)\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\left(\mathsf{neg}\left(b\right)\right) \cdot \left(\mathsf{neg}\left(b\right)\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} \cdot \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}} \cdot a}} \]
      10. metadata-evalN/A

        \[\leadsto \frac{\color{blue}{\frac{1}{2}}}{\frac{\left(\mathsf{neg}\left(b\right)\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\left(\mathsf{neg}\left(b\right)\right) \cdot \left(\mathsf{neg}\left(b\right)\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} \cdot \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}} \cdot a} \]
    4. Applied rewrites86.9%

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

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

    if 0.0269999999999999997 < b

    1. Initial program 51.1%

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. lift-/.f64N/A

        \[\leadsto \color{blue}{\frac{\left(\mathsf{neg}\left(b\right)\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}} \]
      2. div-invN/A

        \[\leadsto \color{blue}{\left(\left(\mathsf{neg}\left(b\right)\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right) \cdot \frac{1}{2 \cdot a}} \]
      3. lift-*.f64N/A

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

        \[\leadsto \left(\left(\mathsf{neg}\left(b\right)\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right) \cdot \color{blue}{\frac{\frac{1}{2}}{a}} \]
      5. metadata-evalN/A

        \[\leadsto \left(\left(\mathsf{neg}\left(b\right)\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right) \cdot \frac{\color{blue}{\frac{1}{2}}}{a} \]
      6. lift-+.f64N/A

        \[\leadsto \color{blue}{\left(\left(\mathsf{neg}\left(b\right)\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right)} \cdot \frac{\frac{1}{2}}{a} \]
      7. flip-+N/A

        \[\leadsto \color{blue}{\frac{\left(\mathsf{neg}\left(b\right)\right) \cdot \left(\mathsf{neg}\left(b\right)\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} \cdot \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\left(\mathsf{neg}\left(b\right)\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}} \cdot \frac{\frac{1}{2}}{a} \]
      8. clear-numN/A

        \[\leadsto \color{blue}{\frac{1}{\frac{\left(\mathsf{neg}\left(b\right)\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\left(\mathsf{neg}\left(b\right)\right) \cdot \left(\mathsf{neg}\left(b\right)\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} \cdot \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}} \cdot \frac{\frac{1}{2}}{a} \]
      9. frac-timesN/A

        \[\leadsto \color{blue}{\frac{1 \cdot \frac{1}{2}}{\frac{\left(\mathsf{neg}\left(b\right)\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\left(\mathsf{neg}\left(b\right)\right) \cdot \left(\mathsf{neg}\left(b\right)\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} \cdot \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}} \cdot a}} \]
      10. metadata-evalN/A

        \[\leadsto \frac{\color{blue}{\frac{1}{2}}}{\frac{\left(\mathsf{neg}\left(b\right)\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\left(\mathsf{neg}\left(b\right)\right) \cdot \left(\mathsf{neg}\left(b\right)\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} \cdot \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}} \cdot a} \]
    4. Applied rewrites51.1%

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

      \[\leadsto \frac{\frac{1}{2}}{\color{blue}{\frac{-1}{2} \cdot \frac{b}{c} + a \cdot \left(a \cdot \left(-1 \cdot \left(a \cdot \left(-1 \cdot \frac{c \cdot \left(-1 \cdot \frac{c}{{b}^{3}} + \frac{1}{2} \cdot \frac{c}{{b}^{3}}\right)}{{b}^{2}} + \left(\frac{-1}{8} \cdot \frac{b \cdot \left(4 \cdot \frac{{c}^{4}}{{b}^{6}} + 16 \cdot \frac{{c}^{4}}{{b}^{6}}\right)}{{c}^{2}} + \frac{{c}^{2}}{{b}^{5}}\right)\right)\right) - \left(-1 \cdot \frac{c}{{b}^{3}} + \frac{1}{2} \cdot \frac{c}{{b}^{3}}\right)\right) + \frac{1}{2} \cdot \frac{1}{b}\right)}} \]
    6. Applied rewrites94.1%

      \[\leadsto \frac{0.5}{\color{blue}{\mathsf{fma}\left(a, \mathsf{fma}\left(a, \left(-a \cdot \left(\mathsf{fma}\left(-0.125, b \cdot \frac{\frac{{c}^{4}}{{b}^{6}} \cdot 20}{c \cdot c}, \frac{c \cdot c}{{b}^{5}}\right) + \left(-c \cdot \frac{\frac{c}{\left(b \cdot b\right) \cdot b} \cdot -0.5}{b \cdot b}\right)\right)\right) - \frac{c}{\left(b \cdot b\right) \cdot b} \cdot -0.5, \frac{0.5}{b}\right), -0.5 \cdot \frac{b}{c}\right)}} \]
    7. Taylor expanded in c around 0

      \[\leadsto \frac{\frac{1}{2}}{\mathsf{fma}\left(a, \mathsf{fma}\left(a, \left(\mathsf{neg}\left(a \cdot \left(-1 \cdot \frac{{c}^{2}}{{b}^{5}}\right)\right)\right) - \frac{c}{\left(b \cdot b\right) \cdot b} \cdot \frac{-1}{2}, \frac{\frac{1}{2}}{b}\right), \frac{-1}{2} \cdot \frac{b}{c}\right)} \]
    8. Step-by-step derivation
      1. Applied rewrites94.1%

        \[\leadsto \frac{0.5}{\mathsf{fma}\left(a, \mathsf{fma}\left(a, \left(-a \cdot \frac{-c \cdot c}{{b}^{5}}\right) - \frac{c}{\left(b \cdot b\right) \cdot b} \cdot -0.5, \frac{0.5}{b}\right), -0.5 \cdot \frac{b}{c}\right)} \]
    9. Recombined 2 regimes into one program.
    10. Final simplification93.7%

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq 0.027:\\ \;\;\;\;\frac{\left(\mathsf{fma}\left(c \cdot -4, a, b \cdot b\right) - b \cdot b\right) \cdot \frac{0.5}{a}}{\sqrt{\mathsf{fma}\left(c \cdot -4, a, b \cdot b\right)} + b}\\ \mathbf{else}:\\ \;\;\;\;\frac{0.5}{\mathsf{fma}\left(a, \mathsf{fma}\left(a, \left(--0.5\right) \cdot \frac{c}{\left(b \cdot b\right) \cdot b} - \frac{\left(-c\right) \cdot c}{{b}^{5}} \cdot a, \frac{0.5}{b}\right), \frac{b}{c} \cdot -0.5\right)}\\ \end{array} \]
    11. Add Preprocessing

    Alternative 2: 92.1% accurate, 0.3× speedup?

    \[\begin{array}{l} \\ \begin{array}{l} t_0 := \mathsf{fma}\left(c \cdot -4, a, b \cdot b\right)\\ t_1 := \left(b \cdot b\right) \cdot b\\ \mathbf{if}\;b \leq 0.027:\\ \;\;\;\;\frac{\left(t\_0 - b \cdot b\right) \cdot \frac{0.5}{a}}{\sqrt{t\_0} + b}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{\left(\left(\left(c \cdot c\right) \cdot c\right) \cdot c\right) \cdot 20}{\left(t\_1 \cdot b\right) \cdot t\_1}, -0.25 \cdot a, \left(-2 \cdot \left(c \cdot c\right)\right) \cdot \frac{c}{t\_1 \cdot \left(b \cdot b\right)}\right), a, \left(-c\right) \cdot \frac{c}{t\_1}\right), a, \frac{-c}{b}\right)\\ \end{array} \end{array} \]
    (FPCore (a b c)
     :precision binary64
     (let* ((t_0 (fma (* c -4.0) a (* b b))) (t_1 (* (* b b) b)))
       (if (<= b 0.027)
         (/ (* (- t_0 (* b b)) (/ 0.5 a)) (+ (sqrt t_0) b))
         (fma
          (fma
           (fma
            (/ (* (* (* (* c c) c) c) 20.0) (* (* t_1 b) t_1))
            (* -0.25 a)
            (* (* -2.0 (* c c)) (/ c (* t_1 (* b b)))))
           a
           (* (- c) (/ c t_1)))
          a
          (/ (- c) b)))))
    double code(double a, double b, double c) {
    	double t_0 = fma((c * -4.0), a, (b * b));
    	double t_1 = (b * b) * b;
    	double tmp;
    	if (b <= 0.027) {
    		tmp = ((t_0 - (b * b)) * (0.5 / a)) / (sqrt(t_0) + b);
    	} else {
    		tmp = fma(fma(fma((((((c * c) * c) * c) * 20.0) / ((t_1 * b) * t_1)), (-0.25 * a), ((-2.0 * (c * c)) * (c / (t_1 * (b * b))))), a, (-c * (c / t_1))), a, (-c / b));
    	}
    	return tmp;
    }
    
    function code(a, b, c)
    	t_0 = fma(Float64(c * -4.0), a, Float64(b * b))
    	t_1 = Float64(Float64(b * b) * b)
    	tmp = 0.0
    	if (b <= 0.027)
    		tmp = Float64(Float64(Float64(t_0 - Float64(b * b)) * Float64(0.5 / a)) / Float64(sqrt(t_0) + b));
    	else
    		tmp = fma(fma(fma(Float64(Float64(Float64(Float64(Float64(c * c) * c) * c) * 20.0) / Float64(Float64(t_1 * b) * t_1)), Float64(-0.25 * a), Float64(Float64(-2.0 * Float64(c * c)) * Float64(c / Float64(t_1 * Float64(b * b))))), a, Float64(Float64(-c) * Float64(c / t_1))), a, Float64(Float64(-c) / b));
    	end
    	return tmp
    end
    
    code[a_, b_, c_] := Block[{t$95$0 = N[(N[(c * -4.0), $MachinePrecision] * a + N[(b * b), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(b * b), $MachinePrecision] * b), $MachinePrecision]}, If[LessEqual[b, 0.027], N[(N[(N[(t$95$0 - N[(b * b), $MachinePrecision]), $MachinePrecision] * N[(0.5 / a), $MachinePrecision]), $MachinePrecision] / N[(N[Sqrt[t$95$0], $MachinePrecision] + b), $MachinePrecision]), $MachinePrecision], N[(N[(N[(N[(N[(N[(N[(N[(c * c), $MachinePrecision] * c), $MachinePrecision] * c), $MachinePrecision] * 20.0), $MachinePrecision] / N[(N[(t$95$1 * b), $MachinePrecision] * t$95$1), $MachinePrecision]), $MachinePrecision] * N[(-0.25 * a), $MachinePrecision] + N[(N[(-2.0 * N[(c * c), $MachinePrecision]), $MachinePrecision] * N[(c / N[(t$95$1 * N[(b * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * a + N[((-c) * N[(c / t$95$1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * a + N[((-c) / b), $MachinePrecision]), $MachinePrecision]]]]
    
    \begin{array}{l}
    
    \\
    \begin{array}{l}
    t_0 := \mathsf{fma}\left(c \cdot -4, a, b \cdot b\right)\\
    t_1 := \left(b \cdot b\right) \cdot b\\
    \mathbf{if}\;b \leq 0.027:\\
    \;\;\;\;\frac{\left(t\_0 - b \cdot b\right) \cdot \frac{0.5}{a}}{\sqrt{t\_0} + b}\\
    
    \mathbf{else}:\\
    \;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{\left(\left(\left(c \cdot c\right) \cdot c\right) \cdot c\right) \cdot 20}{\left(t\_1 \cdot b\right) \cdot t\_1}, -0.25 \cdot a, \left(-2 \cdot \left(c \cdot c\right)\right) \cdot \frac{c}{t\_1 \cdot \left(b \cdot b\right)}\right), a, \left(-c\right) \cdot \frac{c}{t\_1}\right), a, \frac{-c}{b}\right)\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 2 regimes
    2. if b < 0.0269999999999999997

      1. Initial program 85.4%

        \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a} \]
      2. Add Preprocessing
      3. Step-by-step derivation
        1. lift-/.f64N/A

          \[\leadsto \color{blue}{\frac{\left(\mathsf{neg}\left(b\right)\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}} \]
        2. div-invN/A

          \[\leadsto \color{blue}{\left(\left(\mathsf{neg}\left(b\right)\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right) \cdot \frac{1}{2 \cdot a}} \]
        3. lift-*.f64N/A

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

          \[\leadsto \left(\left(\mathsf{neg}\left(b\right)\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right) \cdot \color{blue}{\frac{\frac{1}{2}}{a}} \]
        5. metadata-evalN/A

          \[\leadsto \left(\left(\mathsf{neg}\left(b\right)\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right) \cdot \frac{\color{blue}{\frac{1}{2}}}{a} \]
        6. lift-+.f64N/A

          \[\leadsto \color{blue}{\left(\left(\mathsf{neg}\left(b\right)\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right)} \cdot \frac{\frac{1}{2}}{a} \]
        7. flip-+N/A

          \[\leadsto \color{blue}{\frac{\left(\mathsf{neg}\left(b\right)\right) \cdot \left(\mathsf{neg}\left(b\right)\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} \cdot \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\left(\mathsf{neg}\left(b\right)\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}} \cdot \frac{\frac{1}{2}}{a} \]
        8. clear-numN/A

          \[\leadsto \color{blue}{\frac{1}{\frac{\left(\mathsf{neg}\left(b\right)\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\left(\mathsf{neg}\left(b\right)\right) \cdot \left(\mathsf{neg}\left(b\right)\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} \cdot \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}} \cdot \frac{\frac{1}{2}}{a} \]
        9. frac-timesN/A

          \[\leadsto \color{blue}{\frac{1 \cdot \frac{1}{2}}{\frac{\left(\mathsf{neg}\left(b\right)\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\left(\mathsf{neg}\left(b\right)\right) \cdot \left(\mathsf{neg}\left(b\right)\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} \cdot \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}} \cdot a}} \]
        10. metadata-evalN/A

          \[\leadsto \frac{\color{blue}{\frac{1}{2}}}{\frac{\left(\mathsf{neg}\left(b\right)\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\left(\mathsf{neg}\left(b\right)\right) \cdot \left(\mathsf{neg}\left(b\right)\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} \cdot \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}} \cdot a} \]
      4. Applied rewrites85.4%

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

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

      if 0.0269999999999999997 < b

      1. Initial program 52.7%

        \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a} \]
      2. Add Preprocessing
      3. Taylor expanded in a around 0

        \[\leadsto \color{blue}{-1 \cdot \frac{c}{b} + a \cdot \left(-1 \cdot \frac{{c}^{2}}{{b}^{3}} + a \cdot \left(-2 \cdot \frac{{c}^{3}}{{b}^{5}} + \frac{-1}{4} \cdot \frac{a \cdot \left(4 \cdot \frac{{c}^{4}}{{b}^{6}} + 16 \cdot \frac{{c}^{4}}{{b}^{6}}\right)}{b}\right)\right)} \]
      4. Applied rewrites92.5%

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

        \[\leadsto \mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{20 \cdot \left(\left(\left(c \cdot c\right) \cdot c\right) \cdot c\right)}{\left(\left(b \cdot b\right) \cdot b\right) \cdot \left(\left(\left(b \cdot b\right) \cdot b\right) \cdot b\right)}, a \cdot -0.25, \frac{c}{\left(\left(b \cdot b\right) \cdot b\right) \cdot \left(b \cdot b\right)} \cdot \left(\left(c \cdot c\right) \cdot -2\right)\right), a, \left(-c\right) \cdot \frac{c}{\left(b \cdot b\right) \cdot b}\right), a, \frac{-c}{b}\right) \]
    3. Recombined 2 regimes into one program.
    4. Final simplification92.1%

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq 0.027:\\ \;\;\;\;\frac{\left(\mathsf{fma}\left(c \cdot -4, a, b \cdot b\right) - b \cdot b\right) \cdot \frac{0.5}{a}}{\sqrt{\mathsf{fma}\left(c \cdot -4, a, b \cdot b\right)} + b}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{\left(\left(\left(c \cdot c\right) \cdot c\right) \cdot c\right) \cdot 20}{\left(\left(\left(b \cdot b\right) \cdot b\right) \cdot b\right) \cdot \left(\left(b \cdot b\right) \cdot b\right)}, -0.25 \cdot a, \left(-2 \cdot \left(c \cdot c\right)\right) \cdot \frac{c}{\left(\left(b \cdot b\right) \cdot b\right) \cdot \left(b \cdot b\right)}\right), a, \left(-c\right) \cdot \frac{c}{\left(b \cdot b\right) \cdot b}\right), a, \frac{-c}{b}\right)\\ \end{array} \]
    5. Add Preprocessing

    Reproduce

    ?
    herbie shell --seed 2024229 
    (FPCore (a b c)
      :name "Quadratic roots, narrow range"
      :precision binary64
      :pre (and (and (and (< 1.0536712127723509e-8 a) (< a 94906265.62425156)) (and (< 1.0536712127723509e-8 b) (< b 94906265.62425156))) (and (< 1.0536712127723509e-8 c) (< c 94906265.62425156)))
      (/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))