Average Error: 33.7 → 7.0
Time: 54.6s
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 -2.8459694695487 \cdot 10^{+103}:\\ \;\;\;\;\frac{-c}{b}\\ \mathbf{elif}\;b \le -4.1667813469937575 \cdot 10^{-269}:\\ \;\;\;\;\frac{1}{\sqrt{(\left(a \cdot -4\right) \cdot c + \left(b \cdot b\right))_*} + \left(-b\right)} \cdot \left(2 \cdot c\right)\\ \mathbf{elif}\;b \le 4.8644289703106543 \cdot 10^{+129}:\\ \;\;\;\;\frac{1}{a \cdot 2} \cdot \left(\left(-b\right) - \sqrt{(\left(a \cdot -4\right) \cdot c + \left(b \cdot b\right))_*}\right)\\ \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.7
Target20.9
Herbie7.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 4 regimes
  2. if b < -2.8459694695487e+103

    1. Initial program 59.2

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

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

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

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

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

    if -2.8459694695487e+103 < b < -4.1667813469937575e-269

    1. Initial program 35.0

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

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

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

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

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

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

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

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

    if -4.1667813469937575e-269 < b < 4.8644289703106543e+129

    1. Initial program 9.5

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

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

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

    if 4.8644289703106543e+129 < b

    1. Initial program 52.0

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -2.8459694695487 \cdot 10^{+103}:\\ \;\;\;\;\frac{-c}{b}\\ \mathbf{elif}\;b \le -4.1667813469937575 \cdot 10^{-269}:\\ \;\;\;\;\frac{1}{\sqrt{(\left(a \cdot -4\right) \cdot c + \left(b \cdot b\right))_*} + \left(-b\right)} \cdot \left(2 \cdot c\right)\\ \mathbf{elif}\;b \le 4.8644289703106543 \cdot 10^{+129}:\\ \;\;\;\;\frac{1}{a \cdot 2} \cdot \left(\left(-b\right) - \sqrt{(\left(a \cdot -4\right) \cdot c + \left(b \cdot b\right))_*}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \end{array}\]

Runtime

Time bar (total: 54.6s)Debug logProfile

herbie shell --seed 2018336 +o rules:numerics
(FPCore (a b c)
  :name "The quadratic formula (r2)"

  :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)))