Average Error: 33.4 → 10.0
Time: 30.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 -1.4724387140230096 \cdot 10^{-17}:\\ \;\;\;\;-\frac{c}{b}\\ \mathbf{elif}\;b \le 3.6247124144787303 \cdot 10^{+143}:\\ \;\;\;\;\frac{\sqrt{(a \cdot \left(c \cdot -4\right) + \left(b \cdot b\right))_*} + b}{a} \cdot \frac{-1}{2}\\ \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.4
Target20.8
Herbie10.0
\[\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 3 regimes
  2. if b < -1.4724387140230096e-17

    1. Initial program 54.1

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

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

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

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

    if -1.4724387140230096e-17 < b < 3.6247124144787303e+143

    1. Initial program 14.6

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

      \[\leadsto \color{blue}{\frac{\frac{\left(-b\right) - \sqrt{(\left(a \cdot c\right) \cdot -4 + \left(b \cdot b\right))_*}}{2}}{a}}\]
    3. Using strategy rm
    4. Applied div-inv14.7

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

      \[\leadsto \frac{\left(-b\right) - \sqrt{(\left(a \cdot c\right) \cdot -4 + \left(b \cdot b\right))_*}}{2} \cdot \color{blue}{{\left(\frac{1}{a}\right)}^{1}}\]
    7. Applied pow114.7

      \[\leadsto \color{blue}{{\left(\frac{\left(-b\right) - \sqrt{(\left(a \cdot c\right) \cdot -4 + \left(b \cdot b\right))_*}}{2}\right)}^{1}} \cdot {\left(\frac{1}{a}\right)}^{1}\]
    8. Applied pow-prod-down14.7

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

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

    if 3.6247124144787303e+143 < b

    1. Initial program 56.8

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

      \[\leadsto \color{blue}{\frac{\frac{\left(-b\right) - \sqrt{(\left(a \cdot c\right) \cdot -4 + \left(b \cdot b\right))_*}}{2}}{a}}\]
    3. Using strategy rm
    4. Applied div-inv56.8

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -1.4724387140230096 \cdot 10^{-17}:\\ \;\;\;\;-\frac{c}{b}\\ \mathbf{elif}\;b \le 3.6247124144787303 \cdot 10^{+143}:\\ \;\;\;\;\frac{\sqrt{(a \cdot \left(c \cdot -4\right) + \left(b \cdot b\right))_*} + b}{a} \cdot \frac{-1}{2}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \end{array}\]

Reproduce

herbie shell --seed 2019053 +o rules:numerics
(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)))