Average Error: 32.8 → 9.1
Time: 35.8s
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.4418812687735028 \cdot 10^{+162}:\\ \;\;\;\;\frac{\left(c \cdot a\right) \cdot 4}{\left(a \cdot 2\right) \cdot (\left(\frac{2}{b}\right) \cdot \left(c \cdot a\right) + \left(-2 \cdot b\right))_*}\\ \mathbf{elif}\;b \le -2.312521560308525 \cdot 10^{-292}:\\ \;\;\;\;\frac{\frac{c}{2} \cdot 4}{\sqrt{(\left(a \cdot -4\right) \cdot c + \left(b \cdot b\right))_*} - b}\\ \mathbf{elif}\;b \le 1.2367652643144536 \cdot 10^{+136}:\\ \;\;\;\;\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

Original32.8
Target20.4
Herbie9.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 < -1.4418812687735028e+162

    1. Initial program 62.9

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

      \[\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 flip--62.9

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

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

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

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

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

    if -1.4418812687735028e+162 < b < -2.312521560308525e-292

    1. Initial program 34.3

      \[\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
    2. Initial simplification34.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 flip--34.4

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

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

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

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

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

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

    if -2.312521560308525e-292 < b < 1.2367652643144536e+136

    1. Initial program 9.3

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

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

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

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

    if 1.2367652643144536e+136 < b

    1. Initial program 53.8

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

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

      \[\leadsto \color{blue}{-1 \cdot \frac{b}{a}}\]
    4. Simplified2.8

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -1.4418812687735028 \cdot 10^{+162}:\\ \;\;\;\;\frac{\left(c \cdot a\right) \cdot 4}{\left(a \cdot 2\right) \cdot (\left(\frac{2}{b}\right) \cdot \left(c \cdot a\right) + \left(-2 \cdot b\right))_*}\\ \mathbf{elif}\;b \le -2.312521560308525 \cdot 10^{-292}:\\ \;\;\;\;\frac{\frac{c}{2} \cdot 4}{\sqrt{(\left(a \cdot -4\right) \cdot c + \left(b \cdot b\right))_*} - b}\\ \mathbf{elif}\;b \le 1.2367652643144536 \cdot 10^{+136}:\\ \;\;\;\;\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

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