Average Error: 34.5 → 6.9
Time: 5.0s
Precision: binary64
\[\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 -4.7868277875676773 \cdot 10^{101}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le -2.459714357747724 \cdot 10^{-297}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)} - b}{a \cdot 2}\\ \mathbf{elif}\;b \le 2.4805071658220791 \cdot 10^{102}:\\ \;\;\;\;\frac{4}{b + \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}} \cdot \frac{-c}{2}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} \cdot -1\\ \end{array}\]

Error

Bits error versus a

Bits error versus b

Bits error versus c

Target

Original34.5
Target21.5
Herbie6.9
\[\begin{array}{l} \mathbf{if}\;b \lt 0.0:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{a \cdot \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 < -4.7868277875676773e101

    1. Initial program 47.1

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

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

      \[\leadsto \color{blue}{1 \cdot \frac{c}{b} - 1 \cdot \frac{b}{a}}\]
    4. Simplified4.1

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

    if -4.7868277875676773e101 < b < -2.459714357747724e-297

    1. Initial program 9.5

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

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

    if -2.459714357747724e-297 < b < 2.4805071658220791e102

    1. Initial program 32.0

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

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

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

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

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

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

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

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

      \[\leadsto -\color{blue}{\frac{4}{b + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}} \cdot \frac{a \cdot c}{a \cdot 2}}\]
    12. Using strategy rm
    13. Applied associate-/r*15.5

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

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

    if 2.4805071658220791e102 < b

    1. Initial program 59.5

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -4.7868277875676773 \cdot 10^{101}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le -2.459714357747724 \cdot 10^{-297}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)} - b}{a \cdot 2}\\ \mathbf{elif}\;b \le 2.4805071658220791 \cdot 10^{102}:\\ \;\;\;\;\frac{4}{b + \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}} \cdot \frac{-c}{2}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} \cdot -1\\ \end{array}\]

Reproduce

herbie shell --seed 2020182 
(FPCore (a b c)
  :name "quadp (p42, positive)"
  :precision binary64

  :herbie-target
  (if (< b 0.0) (/ (+ (neg b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)) (/ c (* a (/ (- (neg b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))))

  (/ (+ (neg b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))