Average Error: 34.3 → 6.7
Time: 4.7s
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 -3.89006540944298138 \cdot 10^{133}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le -1.1137175916725923 \cdot 10^{-303}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}}{a \cdot 2} - \frac{b}{a \cdot 2}\\ \mathbf{elif}\;b \le 6.19211077655463949 \cdot 10^{103}:\\ \;\;\;\;c \cdot \frac{\frac{-4}{b + \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}}}{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.3
Target21.2
Herbie6.7
\[\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 < -3.89006540944298138e133

    1. Initial program 57.1

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

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

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

    if -3.89006540944298138e133 < b < -1.1137175916725923e-303

    1. Initial program 9.4

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

      \[\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 div-sub9.4

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

    if -1.1137175916725923e-303 < b < 6.19211077655463949e103

    1. Initial program 32.3

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

      \[\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.4

      \[\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.1

      \[\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.1

      \[\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.1

      \[\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.1

      \[\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. Simplified16.2

      \[\leadsto \frac{-\color{blue}{\frac{4}{b + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}} \cdot \left(a \cdot c\right)}}{a \cdot 2}\]
    11. Using strategy rm
    12. Applied distribute-frac-neg16.2

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

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

    if 6.19211077655463949e103 < b

    1. Initial program 59.3

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

      \[\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.2

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -3.89006540944298138 \cdot 10^{133}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le -1.1137175916725923 \cdot 10^{-303}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}}{a \cdot 2} - \frac{b}{a \cdot 2}\\ \mathbf{elif}\;b \le 6.19211077655463949 \cdot 10^{103}:\\ \;\;\;\;c \cdot \frac{\frac{-4}{b + \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}}}{2}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} \cdot -1\\ \end{array}\]

Reproduce

herbie shell --seed 2020184 
(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)))