Average Error: 33.9 → 13.2
Time: 2.2m
Precision: 64
Internal Precision: 3392
\[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]
\[\begin{array}{l} \mathbf{if}\;\frac{e^{\left(\sqrt[3]{\log \left(\sqrt{(\left(4 \cdot a\right) \cdot \left(-c\right) + \left(b \cdot b\right))_*} - b\right)} \cdot \sqrt[3]{\log \left(\sqrt{(\left(4 \cdot a\right) \cdot \left(-c\right) + \left(b \cdot b\right))_*} - b\right)}\right) \cdot \sqrt[3]{\log \left(\sqrt{(\left(4 \cdot a\right) \cdot \left(-c\right) + \left(b \cdot b\right))_*} - b\right)}}}{2 \cdot a} \le -7.917343334784756 \cdot 10^{+307}:\\ \;\;\;\;\frac{c}{b + b} \cdot \frac{-4}{2}\\ \mathbf{elif}\;\frac{e^{\left(\sqrt[3]{\log \left(\sqrt{(\left(4 \cdot a\right) \cdot \left(-c\right) + \left(b \cdot b\right))_*} - b\right)} \cdot \sqrt[3]{\log \left(\sqrt{(\left(4 \cdot a\right) \cdot \left(-c\right) + \left(b \cdot b\right))_*} - b\right)}\right) \cdot \sqrt[3]{\log \left(\sqrt{(\left(4 \cdot a\right) \cdot \left(-c\right) + \left(b \cdot b\right))_*} - b\right)}}}{2 \cdot a} \le -1.3311966504130146 \cdot 10^{-250}:\\ \;\;\;\;\frac{\sqrt{(\left(4 \cdot a\right) \cdot \left(-c\right) + \left(b \cdot b\right))_*} - b}{2 \cdot a}\\ \mathbf{elif}\;\frac{e^{\left(\sqrt[3]{\log \left(\sqrt{(\left(4 \cdot a\right) \cdot \left(-c\right) + \left(b \cdot b\right))_*} - b\right)} \cdot \sqrt[3]{\log \left(\sqrt{(\left(4 \cdot a\right) \cdot \left(-c\right) + \left(b \cdot b\right))_*} - b\right)}\right) \cdot \sqrt[3]{\log \left(\sqrt{(\left(4 \cdot a\right) \cdot \left(-c\right) + \left(b \cdot b\right))_*} - b\right)}}}{2 \cdot a} \le 1.668472586871161 \cdot 10^{-297}:\\ \;\;\;\;\frac{c}{b + b} \cdot \frac{-4}{2}\\ \mathbf{elif}\;\frac{e^{\left(\sqrt[3]{\log \left(\sqrt{(\left(4 \cdot a\right) \cdot \left(-c\right) + \left(b \cdot b\right))_*} - b\right)} \cdot \sqrt[3]{\log \left(\sqrt{(\left(4 \cdot a\right) \cdot \left(-c\right) + \left(b \cdot b\right))_*} - b\right)}\right) \cdot \sqrt[3]{\log \left(\sqrt{(\left(4 \cdot a\right) \cdot \left(-c\right) + \left(b \cdot b\right))_*} - b\right)}}}{2 \cdot a} \le 6.985866127558625 \cdot 10^{+307}:\\ \;\;\;\;\frac{\sqrt{(\left(4 \cdot a\right) \cdot \left(-c\right) + \left(b \cdot b\right))_*} - b}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b + b} \cdot \frac{-4}{2}\\ \end{array}\]

Error

Bits error versus a

Bits error versus b

Bits error versus c

Target

Original33.9
Target21.1
Herbie13.2
\[\begin{array}{l} \mathbf{if}\;b \lt 0:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{a \cdot \frac{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}}\\ \end{array}\]

Derivation

  1. Split input into 2 regimes
  2. if (/ (exp (* (* (cbrt (log (- (sqrt (fma (* 4 a) (- c) (* b b))) b))) (cbrt (log (- (sqrt (fma (* 4 a) (- c) (* b b))) b)))) (cbrt (log (- (sqrt (fma (* 4 a) (- c) (* b b))) b))))) (* 2 a)) < -7.917343334784756e+307 or -1.3311966504130146e-250 < (/ (exp (* (* (cbrt (log (- (sqrt (fma (* 4 a) (- c) (* b b))) b))) (cbrt (log (- (sqrt (fma (* 4 a) (- c) (* b b))) b)))) (cbrt (log (- (sqrt (fma (* 4 a) (- c) (* b b))) b))))) (* 2 a)) < 1.668472586871161e-297 or 6.985866127558625e+307 < (/ (exp (* (* (cbrt (log (- (sqrt (fma (* 4 a) (- c) (* b b))) b))) (cbrt (log (- (sqrt (fma (* 4 a) (- c) (* b b))) b)))) (cbrt (log (- (sqrt (fma (* 4 a) (- c) (* b b))) b))))) (* 2 a))

    1. Initial program 59.1

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

      \[\leadsto \color{blue}{\frac{\sqrt{(\left(4 \cdot a\right) \cdot \left(-c\right) + \left(b \cdot b\right))_*} - b}{2 \cdot a}}\]
    3. Using strategy rm
    4. Applied div-inv59.1

      \[\leadsto \color{blue}{\left(\sqrt{(\left(4 \cdot a\right) \cdot \left(-c\right) + \left(b \cdot b\right))_*} - b\right) \cdot \frac{1}{2 \cdot a}}\]
    5. Using strategy rm
    6. Applied flip--59.5

      \[\leadsto \color{blue}{\frac{\sqrt{(\left(4 \cdot a\right) \cdot \left(-c\right) + \left(b \cdot b\right))_*} \cdot \sqrt{(\left(4 \cdot a\right) \cdot \left(-c\right) + \left(b \cdot b\right))_*} - b \cdot b}{\sqrt{(\left(4 \cdot a\right) \cdot \left(-c\right) + \left(b \cdot b\right))_*} + b}} \cdot \frac{1}{2 \cdot a}\]
    7. Applied associate-*l/59.5

      \[\leadsto \color{blue}{\frac{\left(\sqrt{(\left(4 \cdot a\right) \cdot \left(-c\right) + \left(b \cdot b\right))_*} \cdot \sqrt{(\left(4 \cdot a\right) \cdot \left(-c\right) + \left(b \cdot b\right))_*} - b \cdot b\right) \cdot \frac{1}{2 \cdot a}}{\sqrt{(\left(4 \cdot a\right) \cdot \left(-c\right) + \left(b \cdot b\right))_*} + b}}\]
    8. Applied simplify38.4

      \[\leadsto \frac{\color{blue}{\frac{\left(a \cdot 4\right) \cdot \left(-c\right)}{2 \cdot a}}}{\sqrt{(\left(4 \cdot a\right) \cdot \left(-c\right) + \left(b \cdot b\right))_*} + b}\]
    9. Taylor expanded around 0 28.2

      \[\leadsto \frac{\frac{\left(a \cdot 4\right) \cdot \left(-c\right)}{2 \cdot a}}{\color{blue}{b} + b}\]
    10. Applied simplify21.8

      \[\leadsto \color{blue}{\frac{c}{b + b} \cdot \frac{-4}{2}}\]

    if -7.917343334784756e+307 < (/ (exp (* (* (cbrt (log (- (sqrt (fma (* 4 a) (- c) (* b b))) b))) (cbrt (log (- (sqrt (fma (* 4 a) (- c) (* b b))) b)))) (cbrt (log (- (sqrt (fma (* 4 a) (- c) (* b b))) b))))) (* 2 a)) < -1.3311966504130146e-250 or 1.668472586871161e-297 < (/ (exp (* (* (cbrt (log (- (sqrt (fma (* 4 a) (- c) (* b b))) b))) (cbrt (log (- (sqrt (fma (* 4 a) (- c) (* b b))) b)))) (cbrt (log (- (sqrt (fma (* 4 a) (- c) (* b b))) b))))) (* 2 a)) < 6.985866127558625e+307

    1. Initial program 2.4

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

      \[\leadsto \color{blue}{\frac{\sqrt{(\left(4 \cdot a\right) \cdot \left(-c\right) + \left(b \cdot b\right))_*} - b}{2 \cdot a}}\]
  3. Recombined 2 regimes into one program.

Runtime

Time bar (total: 2.2m)Debug logProfile

herbie shell --seed 2018208 +o rules:numerics
(FPCore (a b c)
  :name "The quadratic formula (r1)"

  :herbie-target
  (if (< b 0) (/ (+ (- b) (sqrt (- (* b b) (* (* 4 a) c)))) (* 2 a)) (/ c (* a (/ (- (- b) (sqrt (- (* b b) (* (* 4 a) c)))) (* 2 a)))))

  (/ (+ (- b) (sqrt (- (* b b) (* (* 4 a) c)))) (* 2 a)))