Average Error: 33.7 → 6.9
Time: 19.5s
Precision: 64
Internal Precision: 128
\[\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 -9.221915569974277 \cdot 10^{+152}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \le -1.409465968557148 \cdot 10^{-275}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - \left(c \cdot 4\right) \cdot a} - b}{a \cdot 2}\\ \mathbf{elif}\;b \le 3.738519642861093 \cdot 10^{+72}:\\ \;\;\;\;\frac{\frac{c \cdot -4}{2}}{\sqrt{b \cdot b - \left(c \cdot 4\right) \cdot a} + b}\\ \mathbf{else}:\\ \;\;\;\;\frac{-c}{b}\\ \end{array}\]

Error

Bits error versus a

Bits error versus b

Bits error versus c

Target

Original33.7
Target20.6
Herbie6.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 4 regimes
  2. if b < -9.221915569974277e+152

    1. Initial program 60.4

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

      \[\leadsto \color{blue}{\frac{\sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4} - b}{2 \cdot a}}\]
    3. Taylor expanded around -inf 60.4

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

      \[\leadsto \frac{\sqrt{\color{blue}{b \cdot b - a \cdot \left(4 \cdot c\right)}} - b}{2 \cdot a}\]
    5. Taylor expanded around -inf 2.5

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

    if -9.221915569974277e+152 < b < -1.409465968557148e-275

    1. Initial program 8.5

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

      \[\leadsto \color{blue}{\frac{\sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4} - b}{2 \cdot a}}\]
    3. Taylor expanded around -inf 8.4

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

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

    if -1.409465968557148e-275 < b < 3.738519642861093e+72

    1. Initial program 30.8

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

      \[\leadsto \color{blue}{\frac{\sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4} - b}{2 \cdot a}}\]
    3. Taylor expanded around -inf 30.9

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

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

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

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

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

      \[\leadsto \frac{\color{blue}{\frac{\frac{0 - a \cdot \left(4 \cdot c\right)}{a}}{2}}}{\sqrt{b \cdot b - a \cdot \left(4 \cdot c\right)} + b}\]
    11. Taylor expanded around -inf 9.7

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

    if 3.738519642861093e+72 < b

    1. Initial program 57.3

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

      \[\leadsto \color{blue}{\frac{\sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4} - b}{2 \cdot a}}\]
    3. Taylor expanded around -inf 57.3

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

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

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

      \[\leadsto \color{blue}{-1 \cdot \frac{c}{b}}\]
    8. Simplified3.5

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -9.221915569974277 \cdot 10^{+152}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \le -1.409465968557148 \cdot 10^{-275}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - \left(c \cdot 4\right) \cdot a} - b}{a \cdot 2}\\ \mathbf{elif}\;b \le 3.738519642861093 \cdot 10^{+72}:\\ \;\;\;\;\frac{\frac{c \cdot -4}{2}}{\sqrt{b \cdot b - \left(c \cdot 4\right) \cdot a} + b}\\ \mathbf{else}:\\ \;\;\;\;\frac{-c}{b}\\ \end{array}\]

Reproduce

herbie shell --seed 2019051 
(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)))