Average Error: 28.6 → 5.2
Time: 14.7s
Precision: binary64
Cost: 34372
\[\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)\]
\[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a} \]
\[\begin{array}{l} t_0 := \mathsf{fma}\left(a \cdot c, -4, b \cdot b\right)\\ \mathbf{if}\;b \leq 0.45:\\ \;\;\;\;\frac{t_0 - b \cdot b}{b + \sqrt{t_0}} \cdot \frac{0.5}{a}\\ \mathbf{else}:\\ \;\;\;\;\left(a \cdot a\right) \cdot \left(-2 \cdot \left(\left(c \cdot c\right) \cdot \left(c \cdot {b}^{-5}\right)\right) + a \cdot \frac{-5 \cdot {c}^{4}}{{b}^{7}}\right) - \mathsf{fma}\left(\frac{a}{{b}^{3}}, c \cdot c, \frac{c}{b}\right)\\ \end{array} \]
(FPCore (a b c)
 :precision binary64
 (/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))
(FPCore (a b c)
 :precision binary64
 (let* ((t_0 (fma (* a c) -4.0 (* b b))))
   (if (<= b 0.45)
     (* (/ (- t_0 (* b b)) (+ b (sqrt t_0))) (/ 0.5 a))
     (-
      (*
       (* a a)
       (+
        (* -2.0 (* (* c c) (* c (pow b -5.0))))
        (* a (/ (* -5.0 (pow c 4.0)) (pow b 7.0)))))
      (fma (/ a (pow b 3.0)) (* c c) (/ c b))))))
double code(double a, double b, double c) {
	return (-b + sqrt(((b * b) - ((4.0 * a) * c)))) / (2.0 * a);
}
double code(double a, double b, double c) {
	double t_0 = fma((a * c), -4.0, (b * b));
	double tmp;
	if (b <= 0.45) {
		tmp = ((t_0 - (b * b)) / (b + sqrt(t_0))) * (0.5 / a);
	} else {
		tmp = ((a * a) * ((-2.0 * ((c * c) * (c * pow(b, -5.0)))) + (a * ((-5.0 * pow(c, 4.0)) / pow(b, 7.0))))) - fma((a / pow(b, 3.0)), (c * c), (c / b));
	}
	return tmp;
}
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 code(a, b, c)
	t_0 = fma(Float64(a * c), -4.0, Float64(b * b))
	tmp = 0.0
	if (b <= 0.45)
		tmp = Float64(Float64(Float64(t_0 - Float64(b * b)) / Float64(b + sqrt(t_0))) * Float64(0.5 / a));
	else
		tmp = Float64(Float64(Float64(a * a) * Float64(Float64(-2.0 * Float64(Float64(c * c) * Float64(c * (b ^ -5.0)))) + Float64(a * Float64(Float64(-5.0 * (c ^ 4.0)) / (b ^ 7.0))))) - fma(Float64(a / (b ^ 3.0)), Float64(c * c), Float64(c / b)));
	end
	return tmp
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]
code[a_, b_, c_] := Block[{t$95$0 = N[(N[(a * c), $MachinePrecision] * -4.0 + N[(b * b), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[b, 0.45], N[(N[(N[(t$95$0 - N[(b * b), $MachinePrecision]), $MachinePrecision] / N[(b + N[Sqrt[t$95$0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(0.5 / a), $MachinePrecision]), $MachinePrecision], N[(N[(N[(a * a), $MachinePrecision] * N[(N[(-2.0 * N[(N[(c * c), $MachinePrecision] * N[(c * N[Power[b, -5.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(a * N[(N[(-5.0 * N[Power[c, 4.0], $MachinePrecision]), $MachinePrecision] / N[Power[b, 7.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(N[(a / N[Power[b, 3.0], $MachinePrecision]), $MachinePrecision] * N[(c * c), $MachinePrecision] + N[(c / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}
\begin{array}{l}
t_0 := \mathsf{fma}\left(a \cdot c, -4, b \cdot b\right)\\
\mathbf{if}\;b \leq 0.45:\\
\;\;\;\;\frac{t_0 - b \cdot b}{b + \sqrt{t_0}} \cdot \frac{0.5}{a}\\

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


\end{array}

Error

Derivation

  1. Split input into 2 regimes
  2. if b < 0.450000000000000011

    1. Initial program 11.3

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

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

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

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

    if 0.450000000000000011 < b

    1. Initial program 31.3

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

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

      \[\leadsto \color{blue}{\left(-0.5 \cdot \frac{{\left(-2 \cdot \left({c}^{2} \cdot {a}^{2}\right)\right)}^{2} + 16 \cdot \left({c}^{4} \cdot {a}^{4}\right)}{{b}^{7}} + \left(-2 \cdot \frac{{c}^{2} \cdot {a}^{2}}{{b}^{3}} + \left(-4 \cdot \frac{{c}^{3} \cdot {a}^{3}}{{b}^{5}} + -2 \cdot \frac{c \cdot a}{b}\right)\right)\right)} \cdot \frac{0.5}{a} \]
    4. Simplified4.6

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

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

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

      \[\leadsto \left(a \cdot a\right) \cdot \left(-2 \cdot \color{blue}{\left(\left(c \cdot c\right) \cdot \left(c \cdot {b}^{-5}\right)\right)} + \frac{-5 \cdot {c}^{4}}{{b}^{7}} \cdot a\right) - \mathsf{fma}\left(\frac{a}{{b}^{3}}, c \cdot c, \frac{c}{b}\right) \]
  3. Recombined 2 regimes into one program.
  4. Final simplification5.2

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq 0.45:\\ \;\;\;\;\frac{\mathsf{fma}\left(a \cdot c, -4, b \cdot b\right) - b \cdot b}{b + \sqrt{\mathsf{fma}\left(a \cdot c, -4, b \cdot b\right)}} \cdot \frac{0.5}{a}\\ \mathbf{else}:\\ \;\;\;\;\left(a \cdot a\right) \cdot \left(-2 \cdot \left(\left(c \cdot c\right) \cdot \left(c \cdot {b}^{-5}\right)\right) + a \cdot \frac{-5 \cdot {c}^{4}}{{b}^{7}}\right) - \mathsf{fma}\left(\frac{a}{{b}^{3}}, c \cdot c, \frac{c}{b}\right)\\ \end{array} \]

Alternatives

Alternative 1
Error6.6
Cost20932
\[\begin{array}{l} t_0 := \mathsf{fma}\left(a \cdot c, -4, b \cdot b\right)\\ \mathbf{if}\;b \leq 0.45:\\ \;\;\;\;\frac{t_0 - b \cdot b}{b + \sqrt{t_0}} \cdot \frac{0.5}{a}\\ \mathbf{else}:\\ \;\;\;\;a \cdot \left(a \cdot \left(-2 \cdot \frac{{c}^{3}}{{b}^{5}}\right) - \frac{c \cdot c}{{b}^{3}}\right) - \frac{c}{b}\\ \end{array} \]
Alternative 2
Error6.7
Cost20740
\[\begin{array}{l} \mathbf{if}\;b \leq 0.45:\\ \;\;\;\;\frac{0.5}{a} \cdot \left(\sqrt{\mathsf{fma}\left(b, b, a \cdot \left(c \cdot -4\right)\right)} - b\right)\\ \mathbf{else}:\\ \;\;\;\;a \cdot \left(a \cdot \left(-2 \cdot \frac{{c}^{3}}{{b}^{5}}\right) - \frac{c \cdot c}{{b}^{3}}\right) - \frac{c}{b}\\ \end{array} \]
Alternative 3
Error9.6
Cost13764
\[\begin{array}{l} \mathbf{if}\;b \leq 65:\\ \;\;\;\;\frac{0.5}{a} \cdot \left(\sqrt{\mathsf{fma}\left(b, b, a \cdot \left(c \cdot -4\right)\right)} - b\right)\\ \mathbf{else}:\\ \;\;\;\;-\mathsf{fma}\left(\frac{c \cdot c}{{b}^{3}}, a, \frac{c}{b}\right)\\ \end{array} \]
Alternative 4
Error9.6
Cost13636
\[\begin{array}{l} \mathbf{if}\;b \leq 65:\\ \;\;\;\;\frac{0.5}{a} \cdot \left(\sqrt{b \cdot b + c \cdot \left(a \cdot -4\right)} - b\right)\\ \mathbf{else}:\\ \;\;\;\;-\mathsf{fma}\left(\frac{c \cdot c}{{b}^{3}}, a, \frac{c}{b}\right)\\ \end{array} \]
Alternative 5
Error9.6
Cost7492
\[\begin{array}{l} \mathbf{if}\;b \leq 65:\\ \;\;\;\;\frac{0.5}{a} \cdot \left(\sqrt{b \cdot b + c \cdot \left(a \cdot -4\right)} - b\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} \cdot \left(-1 - \frac{a \cdot c}{b \cdot b}\right)\\ \end{array} \]
Alternative 6
Error11.7
Cost832
\[\frac{c}{b} \cdot \left(-1 - \frac{a \cdot c}{b \cdot b}\right) \]
Alternative 7
Error22.7
Cost256
\[\frac{-c}{b} \]

Error

Reproduce

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