Average Error: 33.7 → 7.1
Time: 31.4s
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 -3.163170403796047 \cdot 10^{+126}:\\ \;\;\;\;-\frac{c}{b}\\ \mathbf{elif}\;b \le 6.953606363151747 \cdot 10^{-277}:\\ \;\;\;\;\frac{2 \cdot c}{\sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)} + \left(-b\right)}\\ \mathbf{elif}\;b \le 7.145891006680855 \cdot 10^{-06}:\\ \;\;\;\;\left(-\frac{b}{a \cdot 2}\right) - \frac{\sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\left(-\frac{b}{a \cdot 2}\right) - \left(\frac{b}{a} \cdot \frac{1}{2} - \frac{c}{b}\right)\\ \end{array}\]

Error

Bits error versus a

Bits error versus b

Bits error versus c

Target

Original33.7
Target20.7
Herbie7.1
\[\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 < -3.163170403796047e+126

    1. Initial program 60.3

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

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

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

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

    if -3.163170403796047e+126 < b < 6.953606363151747e-277

    1. Initial program 32.5

      \[\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-inv32.6

      \[\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--32.7

      \[\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. Applied associate-*l/32.8

      \[\leadsto \color{blue}{\frac{\left(\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)}\right) \cdot \frac{1}{2 \cdot a}}{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}}\]
    7. Simplified14.5

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

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

    if 6.953606363151747e-277 < b < 7.145891006680855e-06

    1. Initial program 10.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-sub10.2

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

    if 7.145891006680855e-06 < b

    1. Initial program 30.9

      \[\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-sub30.9

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -3.163170403796047 \cdot 10^{+126}:\\ \;\;\;\;-\frac{c}{b}\\ \mathbf{elif}\;b \le 6.953606363151747 \cdot 10^{-277}:\\ \;\;\;\;\frac{2 \cdot c}{\sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)} + \left(-b\right)}\\ \mathbf{elif}\;b \le 7.145891006680855 \cdot 10^{-06}:\\ \;\;\;\;\left(-\frac{b}{a \cdot 2}\right) - \frac{\sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\left(-\frac{b}{a \cdot 2}\right) - \left(\frac{b}{a} \cdot \frac{1}{2} - \frac{c}{b}\right)\\ \end{array}\]

Reproduce

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