Average Error: 32.8 → 8.6
Time: 2.6m
Precision: 64
Internal Precision: 3392
\[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]
\[\begin{array}{l} \mathbf{if}\;b \le -1.1514098544621335 \cdot 10^{+149}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{if}\;b \le 7.62296366921463 \cdot 10^{-119}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} + \left(-b\right)}{2 \cdot a}\\ \mathbf{if}\;b \le 3.128421125733265 \cdot 10^{+92}:\\ \;\;\;\;\frac{\frac{\left(4 \cdot a\right) \cdot \left(-c\right)}{b + \sqrt{(\left(4 \cdot a\right) \cdot \left(-c\right) + \left(b \cdot b\right))_*}}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;-\frac{c}{b}\\ \end{array}\]

Error

Bits error versus a

Bits error versus b

Bits error versus c

Derivation

  1. Split input into 4 regimes
  2. if b < -1.1514098544621335e+149

    1. Initial program 59.2

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

      \[\leadsto \frac{\color{blue}{2 \cdot \frac{a \cdot c}{b} - 2 \cdot b}}{2 \cdot a}\]
    3. Applied simplify2.3

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

    if -1.1514098544621335e+149 < b < 7.62296366921463e-119

    1. Initial program 10.5

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

    if 7.62296366921463e-119 < b < 3.128421125733265e+92

    1. Initial program 40.3

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

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

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

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

    if 3.128421125733265e+92 < b

    1. Initial program 58.2

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

      \[\leadsto \frac{\left(-b\right) + \color{blue}{\left(b - 2 \cdot \frac{a \cdot c}{b}\right)}}{2 \cdot a}\]
    3. Applied simplify2.6

      \[\leadsto \color{blue}{\frac{-c}{\frac{b}{1}}}\]
  3. Recombined 4 regimes into one program.
  4. Applied simplify8.6

    \[\leadsto \color{blue}{\begin{array}{l} \mathbf{if}\;b \le -1.1514098544621335 \cdot 10^{+149}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{if}\;b \le 7.62296366921463 \cdot 10^{-119}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} + \left(-b\right)}{2 \cdot a}\\ \mathbf{if}\;b \le 3.128421125733265 \cdot 10^{+92}:\\ \;\;\;\;\frac{\frac{\left(4 \cdot a\right) \cdot \left(-c\right)}{b + \sqrt{(\left(4 \cdot a\right) \cdot \left(-c\right) + \left(b \cdot b\right))_*}}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;-\frac{c}{b}\\ \end{array}}\]

Runtime

Time bar (total: 2.6m)Debug logProfile

herbie shell --seed 2018296 +o rules:numerics
(FPCore (a b c)
  :name "Quadratic roots, full range"
  (/ (+ (- b) (sqrt (- (* b b) (* (* 4 a) c)))) (* 2 a)))