Average Error: 33.7 → 9.3
Time: 52.0s
Precision: 64
Internal Precision: 3392
\[\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.3243617893262817 \cdot 10^{+154}:\\ \;\;\;\;\frac{\left(a \cdot c\right) \cdot 4}{\left(2 \cdot a\right) \cdot \left((c \cdot \left(\frac{a}{b}\right) + \left(-b\right))_* \cdot 2\right)}\\ \mathbf{elif}\;b \le 3.8069962386538195 \cdot 10^{-241}:\\ \;\;\;\;\frac{\frac{c}{2} \cdot 4}{\sqrt{(\left(-4\right) \cdot \left(a \cdot c\right) + \left(b \cdot b\right))_*} - b}\\ \mathbf{elif}\;b \le 1.1866210097804747 \cdot 10^{+60}:\\ \;\;\;\;\left(\left(-b\right) - \sqrt{b \cdot b - \left(a \cdot c\right) \cdot 4}\right) \cdot \frac{1}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;-\frac{b}{a}\\ \end{array}\]

Error

Bits error versus a

Bits error versus b

Bits error versus c

Target

Original33.7
Target20.6
Herbie9.3
\[\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 < -1.3243617893262817e+154

    1. Initial program 62.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 flip--62.9

      \[\leadsto \frac{\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)}}}}{2 \cdot a}\]
    4. Applied associate-/l/62.9

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

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

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

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

    if -1.3243617893262817e+154 < b < 3.8069962386538195e-241

    1. Initial program 32.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 flip--33.0

      \[\leadsto \frac{\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)}}}}{2 \cdot a}\]
    4. Applied associate-/l/37.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(2 \cdot a\right) \cdot \left(\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}\right)}}\]
    5. Simplified19.8

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

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

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

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

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

    if 3.8069962386538195e-241 < b < 1.1866210097804747e+60

    1. Initial program 8.7

      \[\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-inv8.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.1866210097804747e+60 < b

    1. Initial program 37.7

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

      \[\leadsto \frac{\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)}}}}{2 \cdot a}\]
    4. Applied associate-/l/61.0

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

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

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

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

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

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

      \[\leadsto \color{blue}{-1 \cdot \frac{b}{a}}\]
    13. Simplified5.7

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -1.3243617893262817 \cdot 10^{+154}:\\ \;\;\;\;\frac{\left(a \cdot c\right) \cdot 4}{\left(2 \cdot a\right) \cdot \left((c \cdot \left(\frac{a}{b}\right) + \left(-b\right))_* \cdot 2\right)}\\ \mathbf{elif}\;b \le 3.8069962386538195 \cdot 10^{-241}:\\ \;\;\;\;\frac{\frac{c}{2} \cdot 4}{\sqrt{(\left(-4\right) \cdot \left(a \cdot c\right) + \left(b \cdot b\right))_*} - b}\\ \mathbf{elif}\;b \le 1.1866210097804747 \cdot 10^{+60}:\\ \;\;\;\;\left(\left(-b\right) - \sqrt{b \cdot b - \left(a \cdot c\right) \cdot 4}\right) \cdot \frac{1}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;-\frac{b}{a}\\ \end{array}\]

Runtime

Time bar (total: 52.0s)Debug logProfile

herbie shell --seed 2018227 +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)))