Average Error: 33.9 → 13.4
Time: 2.1m
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{{\left(e^{\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)}^{\left(\sqrt[3]{\log \left(\sqrt{(\left(4 \cdot a\right) \cdot \left(-c\right) + \left(b \cdot b\right))_*} - b\right)}\right)}}{2 \cdot a} \le -1.938004317774865 \cdot 10^{+294}:\\ \;\;\;\;\frac{c}{b + b} \cdot \frac{-4}{2}\\ \mathbf{elif}\;\frac{{\left(e^{\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)}^{\left(\sqrt[3]{\log \left(\sqrt{(\left(4 \cdot a\right) \cdot \left(-c\right) + \left(b \cdot b\right))_*} - b\right)}\right)}}{2 \cdot a} \le -1.9236870970777136 \cdot 10^{-296}:\\ \;\;\;\;\frac{\sqrt{(\left(4 \cdot a\right) \cdot \left(-c\right) + \left(b \cdot b\right))_*} - b}{2 \cdot a}\\ \mathbf{elif}\;\frac{{\left(e^{\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)}^{\left(\sqrt[3]{\log \left(\sqrt{(\left(4 \cdot a\right) \cdot \left(-c\right) + \left(b \cdot b\right))_*} - b\right)}\right)}}{2 \cdot a} \le 2.6963135394380778 \cdot 10^{-257}:\\ \;\;\;\;\frac{c}{b + b} \cdot \frac{-4}{2}\\ \mathbf{elif}\;\frac{{\left(e^{\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)}^{\left(\sqrt[3]{\log \left(\sqrt{(\left(4 \cdot a\right) \cdot \left(-c\right) + \left(b \cdot b\right))_*} - b\right)}\right)}}{2 \cdot a} \le 6.027720723072216 \cdot 10^{+299}:\\ \;\;\;\;\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.4
\[\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 (/ (pow (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.938004317774865e+294 or -1.9236870970777136e-296 < (/ (pow (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)) < 2.6963135394380778e-257 or 6.027720723072216e+299 < (/ (pow (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 58.7

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

      \[\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-inv58.7

      \[\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.6

      \[\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.6

      \[\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.6

      \[\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.4

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

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

    if -1.938004317774865e+294 < (/ (pow (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.9236870970777136e-296 or 2.6963135394380778e-257 < (/ (pow (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.027720723072216e+299

    1. Initial program 2.5

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

      \[\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.1m)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)))