Average Error: 33.9 → 16.9
Time: 1.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 3.882128856352725 \cdot 10^{-108}:\\ \;\;\;\;\frac{1}{\frac{a}{\sqrt{(\left(a \cdot 4\right) \cdot \left(-c\right) + \left(b \cdot b\right))_*} - b} \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{-\frac{b}{c}}\\ \end{array}\]

Error

Bits error versus a

Bits error versus b

Bits error versus c

Target

Original33.9
Target20.9
Herbie16.9
\[\begin{array}{l} \mathbf{if}\;b \lt 0:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{a \cdot \frac{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}}\\ \end{array}\]

Derivation

  1. Split input into 2 regimes
  2. if b < 3.882128856352725e-108

    1. Initial program 20.9

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

      \[\leadsto \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 *-un-lft-identity20.9

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

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

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

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

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

    if 3.882128856352725e-108 < b

    1. Initial program 51.8

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

      \[\leadsto \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 *-un-lft-identity51.8

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

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

      \[\leadsto \frac{1}{\color{blue}{-1 \cdot \frac{b}{c}}}\]
    7. Simplified11.1

      \[\leadsto \frac{1}{\color{blue}{\frac{-b}{c}}}\]
  3. Recombined 2 regimes into one program.
  4. Final simplification16.9

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le 3.882128856352725 \cdot 10^{-108}:\\ \;\;\;\;\frac{1}{\frac{a}{\sqrt{(\left(a \cdot 4\right) \cdot \left(-c\right) + \left(b \cdot b\right))_*} - b} \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{-\frac{b}{c}}\\ \end{array}\]

Runtime

Time bar (total: 1.6m)Debug logProfile

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

  :herbie-target
  (if (< b 0) (/ (+ (- b) (sqrt (- (* b b) (* (* 4 a) c)))) (* 2 a)) (/ c (* a (/ (- (- b) (sqrt (- (* b b) (* (* 4 a) c)))) (* 2 a)))))

  (/ (+ (- b) (sqrt (- (* b b) (* (* 4 a) c)))) (* 2 a)))