Average Error: 34.4 → 7.1
Time: 4.6s
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 -7.0263009498684819 \cdot 10^{113}:\\ \;\;\;\;-1 \cdot \frac{c}{b}\\ \mathbf{elif}\;b \le -1.90006912712732557 \cdot 10^{-273}:\\ \;\;\;\;\frac{2 \cdot c}{\sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)} - b}\\ \mathbf{elif}\;b \le 1.26218371014522113 \cdot 10^{33}:\\ \;\;\;\;\left(\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}\right) \cdot \frac{1}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \end{array}\]

Error

Bits error versus a

Bits error versus b

Bits error versus c

Target

Original34.4
Target21.3
Herbie7.1
\[\begin{array}{l} \mathbf{if}\;b \lt 0.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 < -7.0263009498684819e113

    1. Initial program 60.3

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

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

    if -7.0263009498684819e113 < b < -1.90006912712732557e-273

    1. Initial program 34.2

      \[\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
    2. Using strategy rm
    3. Applied div-inv34.2

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

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

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

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

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

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

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

    if -1.90006912712732557e-273 < b < 1.26218371014522113e33

    1. Initial program 10.8

      \[\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
    2. Using strategy rm
    3. Applied div-inv10.9

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

    if 1.26218371014522113e33 < b

    1. Initial program 36.6

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -7.0263009498684819 \cdot 10^{113}:\\ \;\;\;\;-1 \cdot \frac{c}{b}\\ \mathbf{elif}\;b \le -1.90006912712732557 \cdot 10^{-273}:\\ \;\;\;\;\frac{2 \cdot c}{\sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)} - b}\\ \mathbf{elif}\;b \le 1.26218371014522113 \cdot 10^{33}:\\ \;\;\;\;\left(\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}\right) \cdot \frac{1}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \end{array}\]

Reproduce

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

  :herbie-target
  (if (< b 0.0) (/ 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)))

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