Average Error: 33.3 → 6.4
Time: 28.8s
Precision: 64
Internal Precision: 128
\[\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 -5.855495265453979 \cdot 10^{+118}:\\ \;\;\;\;-\frac{c}{b}\\ \mathbf{elif}\;b \le -4.411709356294081 \cdot 10^{-220}:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) + \sqrt{b \cdot b - a \cdot \left(4 \cdot c\right)}}\\ \mathbf{elif}\;b \le 2.769430935392486 \cdot 10^{+93}:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - a \cdot \left(4 \cdot c\right)}}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(\frac{c}{b} \cdot a - b\right) \cdot 2}{a \cdot 2}\\ \end{array}\]

Error

Bits error versus a

Bits error versus b

Bits error versus c

Target

Original33.3
Target20.3
Herbie6.4
\[\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 < -5.855495265453979e+118

    1. Initial program 59.8

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

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

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

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

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

    if -5.855495265453979e+118 < b < -4.411709356294081e-220

    1. Initial program 35.8

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

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

      \[\leadsto \frac{\left(-b\right) - \sqrt{\color{blue}{b \cdot b - a \cdot \left(4 \cdot c\right)}}}{2 \cdot a}\]
    4. Using strategy rm
    5. Applied div-inv35.9

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

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

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

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

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

    if -4.411709356294081e-220 < b < 2.769430935392486e+93

    1. Initial program 10.0

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

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

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

    if 2.769430935392486e+93 < b

    1. Initial program 44.3

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

      \[\leadsto \frac{\color{blue}{2 \cdot \frac{a \cdot c}{b} - 2 \cdot b}}{2 \cdot a}\]
    3. Simplified4.0

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -5.855495265453979 \cdot 10^{+118}:\\ \;\;\;\;-\frac{c}{b}\\ \mathbf{elif}\;b \le -4.411709356294081 \cdot 10^{-220}:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) + \sqrt{b \cdot b - a \cdot \left(4 \cdot c\right)}}\\ \mathbf{elif}\;b \le 2.769430935392486 \cdot 10^{+93}:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - a \cdot \left(4 \cdot c\right)}}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(\frac{c}{b} \cdot a - b\right) \cdot 2}{a \cdot 2}\\ \end{array}\]

Reproduce

herbie shell --seed 2019050 
(FPCore (a b c)
  :name "quadm (p42, negative)"

  :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)))