Average Error: 33.7 → 13.6
Time: 1.9m
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{\sqrt{\sqrt{(\left(4 \cdot a\right) \cdot \left(-c\right) + \left(b \cdot b\right))_*} - b}}{2} \cdot \frac{\sqrt{\sqrt{(\left(4 \cdot a\right) \cdot \left(-c\right) + \left(b \cdot b\right))_*} - b}}{a} \le -4.7404706670867886 \cdot 10^{+278}:\\ \;\;\;\;\frac{-4}{2} \cdot \frac{c}{b + b}\\ \mathbf{if}\;\frac{\sqrt{\sqrt{(\left(4 \cdot a\right) \cdot \left(-c\right) + \left(b \cdot b\right))_*} - b}}{2} \cdot \frac{\sqrt{\sqrt{(\left(4 \cdot a\right) \cdot \left(-c\right) + \left(b \cdot b\right))_*} - b}}{a} \le -6.406169797089137 \cdot 10^{-301}:\\ \;\;\;\;\frac{\sqrt{(\left(4 \cdot a\right) \cdot \left(-c\right) + \left(b \cdot b\right))_*} - b}{2 \cdot a}\\ \mathbf{if}\;\frac{\sqrt{\sqrt{(\left(4 \cdot a\right) \cdot \left(-c\right) + \left(b \cdot b\right))_*} - b}}{2} \cdot \frac{\sqrt{\sqrt{(\left(4 \cdot a\right) \cdot \left(-c\right) + \left(b \cdot b\right))_*} - b}}{a} \le 5.872269164248595 \cdot 10^{-297}:\\ \;\;\;\;\frac{-4}{2} \cdot \frac{c}{b + b}\\ \mathbf{if}\;\frac{\sqrt{\sqrt{(\left(4 \cdot a\right) \cdot \left(-c\right) + \left(b \cdot b\right))_*} - b}}{2} \cdot \frac{\sqrt{\sqrt{(\left(4 \cdot a\right) \cdot \left(-c\right) + \left(b \cdot b\right))_*} - b}}{a} \le 4.2251753098721266 \cdot 10^{+287}:\\ \;\;\;\;\frac{\sqrt{(\left(4 \cdot a\right) \cdot \left(-c\right) + \left(b \cdot b\right))_*} - b}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{-4}{2} \cdot \frac{c}{b + b}\\ \end{array}\]

Error

Bits error versus a

Bits error versus b

Bits error versus c

Target

Original33.7
Target21.0
Herbie13.6
\[\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 (* (/ (sqrt (- (sqrt (fma (* 4 a) (- c) (* b b))) b)) 2) (/ (sqrt (- (sqrt (fma (* 4 a) (- c) (* b b))) b)) a)) < -4.7404706670867886e+278 or -6.406169797089137e-301 < (* (/ (sqrt (- (sqrt (fma (* 4 a) (- c) (* b b))) b)) 2) (/ (sqrt (- (sqrt (fma (* 4 a) (- c) (* b b))) b)) a)) < 5.872269164248595e-297 or 4.2251753098721266e+287 < (* (/ (sqrt (- (sqrt (fma (* 4 a) (- c) (* b b))) b)) 2) (/ (sqrt (- (sqrt (fma (* 4 a) (- c) (* b b))) b)) a))

    1. Initial program 58.5

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]
    2. Applied simplify58.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. Using strategy rm
    4. Applied flip--59.6

      \[\leadsto \frac{\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}}}{2 \cdot a}\]
    5. Applied simplify40.1

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

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

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

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

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

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

    if -4.7404706670867886e+278 < (* (/ (sqrt (- (sqrt (fma (* 4 a) (- c) (* b b))) b)) 2) (/ (sqrt (- (sqrt (fma (* 4 a) (- c) (* b b))) b)) a)) < -6.406169797089137e-301 or 5.872269164248595e-297 < (* (/ (sqrt (- (sqrt (fma (* 4 a) (- c) (* b b))) b)) 2) (/ (sqrt (- (sqrt (fma (* 4 a) (- c) (* b b))) b)) a)) < 4.2251753098721266e+287

    1. Initial program 2.2

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

      \[\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: 1.9m)Debug logProfile

herbie shell --seed 2018214 +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)))