Average Error: 33.6 → 8.6
Time: 3.3m
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}\;b \le -1.3375417917952782 \cdot 10^{+154}:\\ \;\;\;\;\left(-\frac{c}{2}\right) \cdot \left(2 \cdot \frac{b}{a \cdot c} - 2 \cdot \frac{1}{b}\right)\\ \mathbf{if}\;b \le -4.586451634118627 \cdot 10^{-185}:\\ \;\;\;\;\frac{1}{\frac{2 \cdot a}{\sqrt{(\left(4 \cdot a\right) \cdot \left(-c\right) + \left(b \cdot b\right))_*} - b}}\\ \mathbf{if}\;b \le 3.6247124144787303 \cdot 10^{+143}:\\ \;\;\;\;\left(-\frac{c}{2}\right) \cdot \frac{4}{b + \sqrt{(\left(-c\right) \cdot \left(4 \cdot a\right) + \left(b \cdot b\right))_*}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{4}{2}}{2} \cdot \frac{-c}{(\left(\frac{a}{b}\right) \cdot \left(-c\right) + b)_*}\\ \end{array}\]

Error

Bits error versus a

Bits error versus b

Bits error versus c

Target

Original33.6
Target20.6
Herbie8.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 4 regimes
  2. if b < -1.3375417917952782e+154

    1. Initial program 60.9

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]
    2. Applied simplify60.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--62.3

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

      \[\leadsto \frac{\frac{\color{blue}{\left(-c\right) \cdot \left(4 \cdot a\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-identity62.5

      \[\leadsto \frac{\frac{\left(-c\right) \cdot \left(4 \cdot a\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-frac62.4

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

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

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

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

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

    if -1.3375417917952782e+154 < b < -4.586451634118627e-185

    1. Initial program 6.2

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

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

    if -4.586451634118627e-185 < b < 3.6247124144787303e+143

    1. Initial program 31.4

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

      \[\leadsto \frac{\frac{\color{blue}{\left(-c\right) \cdot \left(4 \cdot a\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-identity15.8

      \[\leadsto \frac{\frac{\left(-c\right) \cdot \left(4 \cdot a\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-frac15.6

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

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

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

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

    if 3.6247124144787303e+143 < b

    1. Initial program 61.7

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

      \[\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 simplify35.8

      \[\leadsto \frac{\frac{\color{blue}{\left(-c\right) \cdot \left(4 \cdot a\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-identity35.8

      \[\leadsto \frac{\frac{\left(-c\right) \cdot \left(4 \cdot a\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-frac36.0

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

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

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

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

      \[\leadsto \left(-\frac{c}{2}\right) \cdot \frac{4}{\color{blue}{2 \cdot b - 2 \cdot \frac{a \cdot c}{b}}}\]
    13. Applied simplify1.1

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

Runtime

Time bar (total: 3.3m)Debug logProfile

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