Quadratic roots, narrow range

Percentage Accurate: 55.4% → 91.3%
Time: 12.6s
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.4% 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: 91.3% accurate, 0.2× speedup?

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

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

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(\frac{a \cdot \left(20 \cdot \left(c \cdot \left(c \cdot \left(c \cdot c\right)\right)\right)\right)}{b \cdot \left(b \cdot t\_1\right)}, -0.25, \frac{c \cdot \left(\left(c \cdot c\right) \cdot -2\right)}{t\_1}\right), a \cdot a, \frac{\mathsf{fma}\left(c, c \cdot \frac{a}{b \cdot b}, c\right)}{-b}\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 #s(literal 4 binary64) a) c)))) (*.f64 #s(literal 2 binary64) a)) < -0.095000000000000001

    1. Initial program 85.8%

      \[\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 c around inf

      \[\leadsto \frac{\left(\mathsf{neg}\left(b\right)\right) + \sqrt{\color{blue}{c \cdot \left(\frac{{b}^{2}}{c} - 4 \cdot a\right)}}}{2 \cdot a} \]
    4. Step-by-step derivation
      1. lower-*.f64N/A

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

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

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

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

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

        \[\leadsto \frac{\left(\mathsf{neg}\left(b\right)\right) + \sqrt{c \cdot \color{blue}{\mathsf{fma}\left(a, -4, \frac{{b}^{2}}{c}\right)}}}{2 \cdot a} \]
      7. lower-/.f64N/A

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

        \[\leadsto \frac{\left(\mathsf{neg}\left(b\right)\right) + \sqrt{c \cdot \mathsf{fma}\left(a, -4, \frac{\color{blue}{b \cdot b}}{c}\right)}}{2 \cdot a} \]
      9. lower-*.f6485.7

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

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

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

    if -0.095000000000000001 < (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 #s(literal 4 binary64) a) c)))) (*.f64 #s(literal 2 binary64) a))

    1. Initial program 46.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 rewrites94.8%

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

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

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

Alternative 2: 91.3% accurate, 0.2× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 #s(literal 4 binary64) a) c)))) (*.f64 #s(literal 2 binary64) a)) < -0.095000000000000001

    1. Initial program 79.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 c around inf

      \[\leadsto \frac{\left(\mathsf{neg}\left(b\right)\right) + \sqrt{\color{blue}{c \cdot \left(\frac{{b}^{2}}{c} - 4 \cdot a\right)}}}{2 \cdot a} \]
    4. Step-by-step derivation
      1. lower-*.f64N/A

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

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

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

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

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

        \[\leadsto \frac{\left(\mathsf{neg}\left(b\right)\right) + \sqrt{c \cdot \color{blue}{\mathsf{fma}\left(a, -4, \frac{{b}^{2}}{c}\right)}}}{2 \cdot a} \]
      7. lower-/.f64N/A

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

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

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

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

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

    if -0.095000000000000001 < (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 #s(literal 4 binary64) a) c)))) (*.f64 #s(literal 2 binary64) a))

    1. Initial program 48.6%

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

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

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

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

      \[\leadsto \frac{\mathsf{fma}\left(a \cdot \frac{\left(c \cdot c\right) \cdot \left(a \cdot \left(a \cdot \left(c \cdot c\right)\right)\right)}{\left(b \cdot b\right) \cdot \left(b \cdot \left(b \cdot \left(b \cdot b\right)\right)\right)}, -5, \mathsf{fma}\left(a, \mathsf{fma}\left(-c, \frac{c}{b \cdot b}, \frac{\left(-2 \cdot a\right) \cdot \left(c \cdot \left(c \cdot c\right)\right)}{b \cdot \left(b \cdot \left(b \cdot b\right)\right)}\right), -c\right)\right)}{b} \]
    8. Taylor expanded in b around inf

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

        \[\leadsto \frac{\mathsf{fma}\left(a \cdot \frac{\left(c \cdot c\right) \cdot \left(a \cdot \left(a \cdot \left(c \cdot c\right)\right)\right)}{\left(b \cdot b\right) \cdot \left(b \cdot \left(b \cdot \left(b \cdot b\right)\right)\right)}, -5, \mathsf{fma}\left(a, \frac{\frac{-2 \cdot \left(a \cdot \left(c \cdot \left(c \cdot c\right)\right)\right)}{b \cdot b} - c \cdot c}{b \cdot b}, -c\right)\right)}{b} \]
    10. Recombined 2 regimes into one program.
    11. Final simplification91.3%

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

    Reproduce

    ?
    herbie shell --seed 2024227 
    (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)))