Average Error: 33.5 → 7.2
Time: 4.5m
Precision: 64
Internal Precision: 3456
\[\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 -4.2567282859130756 \cdot 10^{+107}:\\ \;\;\;\;\frac{\frac{c}{b}}{\frac{2}{-2}}\\ \mathbf{if}\;b \le -1.7660590781287138 \cdot 10^{-244}:\\ \;\;\;\;\frac{\frac{-c}{\frac{2}{4}}}{b + \left(-\sqrt{b \cdot b - a \cdot \left(c \cdot 4\right)}\right)}\\ \mathbf{if}\;b \le 5.875811807541756 \cdot 10^{+56}:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - a \cdot \left(c \cdot 4\right)}}{a + a}\\ \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.5
Target20.3
Herbie7.2
\[\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 < -4.2567282859130756e+107

    1. Initial program 58.9

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

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

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

    if -4.2567282859130756e+107 < b < -1.7660590781287138e-244

    1. Initial program 35.4

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

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

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

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

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

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

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

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

    if -1.7660590781287138e-244 < b < 5.875811807541756e+56

    1. Initial program 10.4

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

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

    if 5.875811807541756e+56 < b

    1. Initial program 35.9

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

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

      \[\leadsto \color{blue}{\frac{\frac{c}{b}}{1} - \frac{b}{a}}\]
  3. Recombined 4 regimes into one program.
  4. Removed slow pow expressions.
  5. Applied simplify7.2

    \[\leadsto \color{blue}{\begin{array}{l} \mathbf{if}\;b \le -4.2567282859130756 \cdot 10^{+107}:\\ \;\;\;\;\frac{\frac{c}{b}}{\frac{2}{-2}}\\ \mathbf{if}\;b \le -1.7660590781287138 \cdot 10^{-244}:\\ \;\;\;\;\frac{\frac{-c}{\frac{2}{4}}}{b + \left(-\sqrt{b \cdot b - a \cdot \left(c \cdot 4\right)}\right)}\\ \mathbf{if}\;b \le 5.875811807541756 \cdot 10^{+56}:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - a \cdot \left(c \cdot 4\right)}}{a + a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \end{array}}\]

Runtime

Time bar (total: 4.5m)Debug log

herbie shell --seed '#(1889797285 268396849 4100589100 2067516092 3019009300 3748763710)' +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)))