Average Error: 33.3 → 6.7
Time: 49.5s
Precision: 64
\[\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
\[\begin{array}{l} \mathbf{if}\;b \le -1.0086797704978404 \cdot 10^{+164}:\\ \;\;\;\;-\frac{c}{b}\\ \mathbf{elif}\;b \le -7.561492702273163 \cdot 10^{-267}:\\ \;\;\;\;\frac{1}{\sqrt{b \cdot b + -4 \cdot \left(c \cdot a\right)} - b} \cdot \left(2 \cdot c\right)\\ \mathbf{elif}\;b \le 6.033828240489858 \cdot 10^{+86}:\\ \;\;\;\;\frac{1}{2} \cdot \frac{\left(-b\right) - \sqrt{c \cdot \left(a \cdot -4\right) + b \cdot b}}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \end{array}\]

Error

Bits error versus a

Bits error versus b

Bits error versus c

Target

Original33.3
Target20.5
Herbie6.7
\[\begin{array}{l} \mathbf{if}\;b \lt 0:\\ \;\;\;\;\frac{c}{a \cdot \frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\\ \end{array}\]

Derivation

  1. Split input into 4 regimes
  2. if b < -1.0086797704978404e+164

    1. Initial program 62.9

      \[\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
    2. Taylor expanded around -inf 62.9

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

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

      \[\leadsto \color{blue}{-1 \cdot \frac{c}{b}}\]
    5. Simplified1.0

      \[\leadsto \color{blue}{-\frac{c}{b}}\]

    if -1.0086797704978404e+164 < b < -7.561492702273163e-267

    1. Initial program 36.0

      \[\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
    2. Taylor expanded around -inf 36.0

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

      \[\leadsto \frac{\left(-b\right) - \sqrt{\color{blue}{b \cdot b + \left(c \cdot -4\right) \cdot a}}}{2 \cdot a}\]
    4. Using strategy rm
    5. Applied *-un-lft-identity36.0

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

      \[\leadsto \color{blue}{\frac{1}{\frac{2 \cdot a}{\left(-b\right) - \sqrt{b \cdot b + \left(c \cdot -4\right) \cdot a}}}}\]
    7. Using strategy rm
    8. Applied flip--36.2

      \[\leadsto \frac{1}{\frac{2 \cdot a}{\color{blue}{\frac{\left(-b\right) \cdot \left(-b\right) - \sqrt{b \cdot b + \left(c \cdot -4\right) \cdot a} \cdot \sqrt{b \cdot b + \left(c \cdot -4\right) \cdot a}}{\left(-b\right) + \sqrt{b \cdot b + \left(c \cdot -4\right) \cdot a}}}}}\]
    9. Applied associate-/r/36.2

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

      \[\leadsto \frac{\color{blue}{\left(\sqrt[3]{1} \cdot \sqrt[3]{1}\right) \cdot \sqrt[3]{1}}}{\frac{2 \cdot a}{\left(-b\right) \cdot \left(-b\right) - \sqrt{b \cdot b + \left(c \cdot -4\right) \cdot a} \cdot \sqrt{b \cdot b + \left(c \cdot -4\right) \cdot a}} \cdot \left(\left(-b\right) + \sqrt{b \cdot b + \left(c \cdot -4\right) \cdot a}\right)}\]
    11. Applied times-frac36.2

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

      \[\leadsto \color{blue}{\left(\frac{\frac{1}{2}}{a} \cdot \left(0 - \left(a \cdot c\right) \cdot -4\right)\right)} \cdot \frac{\sqrt[3]{1}}{\left(-b\right) + \sqrt{b \cdot b + \left(c \cdot -4\right) \cdot a}}\]
    13. Simplified15.1

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

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

    if -7.561492702273163e-267 < b < 6.033828240489858e+86

    1. Initial program 9.2

      \[\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
    2. Taylor expanded around -inf 9.2

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

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

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

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

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

      \[\leadsto \frac{1}{\frac{2 \cdot a}{\color{blue}{1 \cdot \left(-b\right)} - 1 \cdot \sqrt{b \cdot b + \left(c \cdot -4\right) \cdot a}}}\]
    10. Applied distribute-lft-out--9.3

      \[\leadsto \frac{1}{\frac{2 \cdot a}{\color{blue}{1 \cdot \left(\left(-b\right) - \sqrt{b \cdot b + \left(c \cdot -4\right) \cdot a}\right)}}}\]
    11. Applied times-frac9.3

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

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

      \[\leadsto \color{blue}{\frac{\sqrt{1}}{\frac{2}{1}} \cdot \frac{\sqrt{1}}{\frac{a}{\left(-b\right) - \sqrt{b \cdot b + \left(c \cdot -4\right) \cdot a}}}}\]
    14. Simplified9.3

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

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

    if 6.033828240489858e+86 < b

    1. Initial program 41.0

      \[\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
    2. Taylor expanded around inf 4.1

      \[\leadsto \color{blue}{\frac{c}{b} - \frac{b}{a}}\]
  3. Recombined 4 regimes into one program.
  4. Final simplification6.7

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -1.0086797704978404 \cdot 10^{+164}:\\ \;\;\;\;-\frac{c}{b}\\ \mathbf{elif}\;b \le -7.561492702273163 \cdot 10^{-267}:\\ \;\;\;\;\frac{1}{\sqrt{b \cdot b + -4 \cdot \left(c \cdot a\right)} - b} \cdot \left(2 \cdot c\right)\\ \mathbf{elif}\;b \le 6.033828240489858 \cdot 10^{+86}:\\ \;\;\;\;\frac{1}{2} \cdot \frac{\left(-b\right) - \sqrt{c \cdot \left(a \cdot -4\right) + b \cdot b}}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \end{array}\]

Reproduce

herbie shell --seed 2019100 
(FPCore (a b c)
  :name "The quadratic formula (r2)"

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

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