Average Error: 33.5 → 13.8
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{\sqrt{{b}^{2} - 4 \cdot \left(c \cdot a\right)} - b}{2 \cdot a} \le -3.893813382866839 \cdot 10^{+302}:\\ \;\;\;\;\frac{\frac{c}{2} \cdot \left(-4\right)}{b + b}\\ \mathbf{if}\;\frac{\sqrt{{b}^{2} - 4 \cdot \left(c \cdot a\right)} - b}{2 \cdot a} \le -2.279763752477715 \cdot 10^{-233}:\\ \;\;\;\;\frac{\sqrt{{b}^{2} - 4 \cdot \left(c \cdot a\right)} - b}{2 \cdot a}\\ \mathbf{if}\;\frac{\sqrt{{b}^{2} - 4 \cdot \left(c \cdot a\right)} - b}{2 \cdot a} \le 9.990245652938313 \cdot 10^{-103}:\\ \;\;\;\;\frac{\frac{c}{2} \cdot \left(-4\right)}{\sqrt{(\left(a \cdot c\right) \cdot \left(-4\right) + \left(b \cdot b\right))_*} + b}\\ \mathbf{if}\;\frac{\sqrt{{b}^{2} - 4 \cdot \left(c \cdot a\right)} - b}{2 \cdot a} \le 7.314979115890435 \cdot 10^{+294}:\\ \;\;\;\;\frac{\sqrt{{b}^{2} - 4 \cdot \left(c \cdot a\right)} - b}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{c}{2} \cdot \left(-4\right)}{b + b}\\ \end{array}\]

Error

Bits error versus a

Bits error versus b

Bits error versus c

Target

Original33.5
Target20.5
Herbie13.8
\[\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 3 regimes
  2. if (/ (- (sqrt (- (pow b 2) (* 4 (* c a)))) b) (* 2 a)) < -3.893813382866839e+302 or 7.314979115890435e+294 < (/ (- (sqrt (- (pow b 2) (* 4 (* c a)))) b) (* 2 a))

    1. Initial program 61.6

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

      \[\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--62.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 simplify50.3

      \[\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 distribute-rgt-neg-out50.3

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

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

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

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

      \[\leadsto -\frac{\left(4 \cdot c\right) \cdot \frac{1}{2}}{\sqrt{\color{blue}{{b}^{2} - 4 \cdot \left(c \cdot a\right)}} + b}\]
    12. Applied simplify50.1

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

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

    if -3.893813382866839e+302 < (/ (- (sqrt (- (pow b 2) (* 4 (* c a)))) b) (* 2 a)) < -2.279763752477715e-233 or 9.990245652938313e-103 < (/ (- (sqrt (- (pow b 2) (* 4 (* c a)))) b) (* 2 a)) < 7.314979115890435e+294

    1. Initial program 4.0

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

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

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

    if -2.279763752477715e-233 < (/ (- (sqrt (- (pow b 2) (* 4 (* c a)))) b) (* 2 a)) < 9.990245652938313e-103

    1. Initial program 41.9

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

      \[\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--44.2

      \[\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 simplify14.5

      \[\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 distribute-rgt-neg-out14.5

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

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

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

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

      \[\leadsto -\frac{\left(4 \cdot c\right) \cdot \frac{1}{2}}{\sqrt{\color{blue}{{b}^{2} - 4 \cdot \left(c \cdot a\right)}} + b}\]
    12. Applied simplify2.7

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

Runtime

Time bar (total: 2.1m)Debug logProfile

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