Average Error: 28.4 → 5.3
Time: 4.8s
Precision: binary64
\[\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 := e^{\log \left(\frac{1}{{c}^{3}}\right) - 5 \cdot \log \left(\frac{1}{b}\right)}\\ \mathbf{if}\;\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}{a \cdot 2} \leq -5:\\ \;\;\;\;\left(\sqrt{\mathsf{fma}\left(c, a \cdot -4, b \cdot b\right)} - b\right) \cdot \frac{0.5}{a}\\ \mathbf{else}:\\ \;\;\;\;-2 \cdot \frac{a \cdot a}{\left(t_0 + \frac{{c}^{3} \cdot t_0}{{b}^{5}}\right) + -1} - \mathsf{fma}\left(5, \frac{{a}^{3}}{{b}^{7}} \cdot {c}^{4}, \mathsf{fma}\left(\frac{c \cdot c}{{b}^{3}}, a, \frac{c}{b}\right)\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 (exp (- (log (/ 1.0 (pow c 3.0))) (* 5.0 (log (/ 1.0 b)))))))
   (if (<= (/ (- (sqrt (- (* b b) (* (* 4.0 a) c))) b) (* a 2.0)) -5.0)
     (* (- (sqrt (fma c (* a -4.0) (* b b))) b) (/ 0.5 a))
     (-
      (* -2.0 (/ (* a a) (+ (+ t_0 (/ (* (pow c 3.0) t_0) (pow b 5.0))) -1.0)))
      (fma
       5.0
       (* (/ (pow a 3.0) (pow b 7.0)) (pow c 4.0))
       (fma (/ (* c c) (pow b 3.0)) a (/ 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 = exp((log((1.0 / pow(c, 3.0))) - (5.0 * log((1.0 / b)))));
	double tmp;
	if (((sqrt(((b * b) - ((4.0 * a) * c))) - b) / (a * 2.0)) <= -5.0) {
		tmp = (sqrt(fma(c, (a * -4.0), (b * b))) - b) * (0.5 / a);
	} else {
		tmp = (-2.0 * ((a * a) / ((t_0 + ((pow(c, 3.0) * t_0) / pow(b, 5.0))) + -1.0))) - fma(5.0, ((pow(a, 3.0) / pow(b, 7.0)) * pow(c, 4.0)), fma(((c * c) / pow(b, 3.0)), a, (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 = exp(Float64(log(Float64(1.0 / (c ^ 3.0))) - Float64(5.0 * log(Float64(1.0 / b)))))
	tmp = 0.0
	if (Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(Float64(4.0 * a) * c))) - b) / Float64(a * 2.0)) <= -5.0)
		tmp = Float64(Float64(sqrt(fma(c, Float64(a * -4.0), Float64(b * b))) - b) * Float64(0.5 / a));
	else
		tmp = Float64(Float64(-2.0 * Float64(Float64(a * a) / Float64(Float64(t_0 + Float64(Float64((c ^ 3.0) * t_0) / (b ^ 5.0))) + -1.0))) - fma(5.0, Float64(Float64((a ^ 3.0) / (b ^ 7.0)) * (c ^ 4.0)), fma(Float64(Float64(c * c) / (b ^ 3.0)), a, 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[Exp[N[(N[Log[N[(1.0 / N[Power[c, 3.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - N[(5.0 * N[Log[N[(1.0 / b), $MachinePrecision]], $MachinePrecision]), $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], -5.0], N[(N[(N[Sqrt[N[(c * N[(a * -4.0), $MachinePrecision] + N[(b * b), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] * N[(0.5 / a), $MachinePrecision]), $MachinePrecision], N[(N[(-2.0 * N[(N[(a * a), $MachinePrecision] / N[(N[(t$95$0 + N[(N[(N[Power[c, 3.0], $MachinePrecision] * t$95$0), $MachinePrecision] / N[Power[b, 5.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(5.0 * N[(N[(N[Power[a, 3.0], $MachinePrecision] / N[Power[b, 7.0], $MachinePrecision]), $MachinePrecision] * N[Power[c, 4.0], $MachinePrecision]), $MachinePrecision] + N[(N[(N[(c * c), $MachinePrecision] / N[Power[b, 3.0], $MachinePrecision]), $MachinePrecision] * a + N[(c / b), $MachinePrecision]), $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 := e^{\log \left(\frac{1}{{c}^{3}}\right) - 5 \cdot \log \left(\frac{1}{b}\right)}\\
\mathbf{if}\;\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}{a \cdot 2} \leq -5:\\
\;\;\;\;\left(\sqrt{\mathsf{fma}\left(c, a \cdot -4, b \cdot b\right)} - b\right) \cdot \frac{0.5}{a}\\

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


\end{array}

Error

Bits error versus a

Bits error versus b

Bits error versus c

Derivation

  1. Split input into 2 regimes
  2. if (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 4 a) c)))) (*.f64 2 a)) < -5

    1. Initial program 10.7

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

      \[\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 0 10.7

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

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

    if -5 < (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 4 a) c)))) (*.f64 2 a))

    1. Initial program 30.7

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

      \[\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(2 \cdot \frac{{c}^{3} \cdot {a}^{2}}{{b}^{5}} + \left(5 \cdot \frac{{c}^{4} \cdot {a}^{3}}{{b}^{7}} + \left(\frac{{c}^{2} \cdot a}{{b}^{3}} + \frac{c}{b}\right)\right)\right)} \]
    4. Simplified4.6

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

      \[\leadsto -2 \cdot \frac{a \cdot a}{\color{blue}{e^{\mathsf{log1p}\left({b}^{5} \cdot {c}^{-3}\right)} - 1}} - \mathsf{fma}\left(5, \frac{{a}^{3}}{{b}^{7}} \cdot {c}^{4}, \mathsf{fma}\left(\frac{c \cdot c}{{b}^{3}}, a, \frac{c}{b}\right)\right) \]
    6. Taylor expanded in b around inf 4.6

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

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

Reproduce

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