Average Error: 33.0 → 6.7
Time: 35.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 -6.613957471284742 \cdot 10^{+130}:\\ \;\;\;\;\frac{-c}{b}\\ \mathbf{elif}\;b \le -9.803705485304467 \cdot 10^{-285}:\\ \;\;\;\;\left(\frac{1}{2} \cdot c\right) \cdot \frac{4}{\sqrt{(\left(a \cdot -4\right) \cdot c + \left(b \cdot b\right))_*} - b}\\ \mathbf{elif}\;b \le 4.353512703078241 \cdot 10^{+76}:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{(\left(a \cdot -4\right) \cdot c + \left(b \cdot b\right))_*}}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\frac{-b}{a}\\ \end{array}\]

Error

Bits error versus a

Bits error versus b

Bits error versus c

Target

Original33.0
Target20.4
Herbie6.7
\[\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 < -6.613957471284742e+130

    1. Initial program 60.5

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

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

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

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

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

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

    if -6.613957471284742e+130 < b < -9.803705485304467e-285

    1. Initial program 33.6

      \[\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
    2. Initial simplification33.6

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

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

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

      \[\leadsto \frac{\color{blue}{\frac{\left(-b\right) \cdot \left(-b\right) - \sqrt{(\left(a \cdot -4\right) \cdot c + \left(b \cdot b\right))_*} \cdot \sqrt{(\left(a \cdot -4\right) \cdot c + \left(b \cdot b\right))_*}}{\left(-b\right) + \sqrt{(\left(a \cdot -4\right) \cdot c + \left(b \cdot b\right))_*}}}}{2 \cdot a}\]
    7. Applied associate-/l/37.9

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

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

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

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

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

    if -9.803705485304467e-285 < b < 4.353512703078241e+76

    1. Initial program 9.6

      \[\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
    2. Initial simplification9.6

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

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

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

    if 4.353512703078241e+76 < b

    1. Initial program 38.9

      \[\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
    2. Initial simplification38.9

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

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

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

      \[\leadsto \frac{\color{blue}{\frac{\left(-b\right) \cdot \left(-b\right) - \sqrt{(\left(a \cdot -4\right) \cdot c + \left(b \cdot b\right))_*} \cdot \sqrt{(\left(a \cdot -4\right) \cdot c + \left(b \cdot b\right))_*}}{\left(-b\right) + \sqrt{(\left(a \cdot -4\right) \cdot c + \left(b \cdot b\right))_*}}}}{2 \cdot a}\]
    7. Applied associate-/l/61.2

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

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

      \[\leadsto \color{blue}{-1 \cdot \frac{b}{a}}\]
    10. Simplified4.6

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -6.613957471284742 \cdot 10^{+130}:\\ \;\;\;\;\frac{-c}{b}\\ \mathbf{elif}\;b \le -9.803705485304467 \cdot 10^{-285}:\\ \;\;\;\;\left(\frac{1}{2} \cdot c\right) \cdot \frac{4}{\sqrt{(\left(a \cdot -4\right) \cdot c + \left(b \cdot b\right))_*} - b}\\ \mathbf{elif}\;b \le 4.353512703078241 \cdot 10^{+76}:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{(\left(a \cdot -4\right) \cdot c + \left(b \cdot b\right))_*}}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\frac{-b}{a}\\ \end{array}\]

Runtime

Time bar (total: 35.8s)Debug logProfile

BaselineHerbieOracleSpan%
Regimes29.56.75.523.995.3%
herbie shell --seed 2018355 +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)))