Average Error: 33.2 → 9.0
Time: 1.7m
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 -2.5377266411070587 \cdot 10^{+153}:\\ \;\;\;\;-\frac{b}{a}\\ \mathbf{if}\;b \le 4.660353967422534 \cdot 10^{-227}:\\ \;\;\;\;\frac{1}{\frac{2 \cdot a}{\sqrt{b \cdot b - \left(a \cdot c\right) \cdot 4} - b}}\\ \mathbf{if}\;b \le 5.182100731555394 \cdot 10^{+96}:\\ \;\;\;\;\frac{1}{\left(\sqrt{b \cdot b - \left(a \cdot c\right) \cdot 4} + b\right) \cdot \frac{2 \cdot a}{\left(-c\right) \cdot \left(4 \cdot a\right)}}\\ \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 < -2.5377266411070587e+153

    1. Initial program 60.7

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

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

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

    if -2.5377266411070587e+153 < b < 4.660353967422534e-227

    1. Initial program 10.0

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

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

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

    if 4.660353967422534e-227 < b < 5.182100731555394e+96

    1. Initial program 34.5

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

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

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

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

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

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

    if 5.182100731555394e+96 < b

    1. Initial program 58.0

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

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

      \[\leadsto \color{blue}{\left(-1\right) \cdot \frac{c}{b}}\]
  3. Recombined 4 regimes into one program.
  4. Applied simplify9.0

    \[\leadsto \color{blue}{\begin{array}{l} \mathbf{if}\;b \le -2.5377266411070587 \cdot 10^{+153}:\\ \;\;\;\;-\frac{b}{a}\\ \mathbf{if}\;b \le 4.660353967422534 \cdot 10^{-227}:\\ \;\;\;\;\frac{1}{\frac{2 \cdot a}{\sqrt{b \cdot b - \left(a \cdot c\right) \cdot 4} - b}}\\ \mathbf{if}\;b \le 5.182100731555394 \cdot 10^{+96}:\\ \;\;\;\;\frac{1}{\left(\sqrt{b \cdot b - \left(a \cdot c\right) \cdot 4} + b\right) \cdot \frac{2 \cdot a}{\left(-c\right) \cdot \left(4 \cdot a\right)}}\\ \mathbf{else}:\\ \;\;\;\;\frac{-c}{b}\\ \end{array}}\]

Runtime

Time bar (total: 1.7m)Debug logProfile

herbie shell --seed '#(1071725047 233389029 2036512464 3988615230 2972226563 1111574017)' 
(FPCore (a b c)
  :name "Quadratic roots, full range"
  (/ (+ (- b) (sqrt (- (* b b) (* (* 4 a) c)))) (* 2 a)))