Average Error: 33.4 → 6.5
Time: 9.1m
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 -4.0906093545612224 \cdot 10^{+106}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \le 2.0687500080625397 \cdot 10^{-307}:\\ \;\;\;\;\frac{\sqrt{(\left(c \cdot a\right) \cdot -4 + \left(b \cdot b\right))_*} + \left(-b\right)}{a \cdot 2}\\ \mathbf{elif}\;b \le 1.756312982163782 \cdot 10^{+91}:\\ \;\;\;\;\frac{c \cdot 2}{\left(-b\right) - \sqrt{(\left(c \cdot a\right) \cdot -4 + \left(b \cdot b\right))_*}}\\ \mathbf{else}:\\ \;\;\;\;-\frac{c}{b}\\ \end{array}\]

Error

Bits error versus a

Bits error versus b

Bits error versus c

Target

Original33.4
Target20.3
Herbie6.5
\[\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 < -4.0906093545612224e+106

    1. Initial program 46.0

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

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

    if -4.0906093545612224e+106 < b < 2.0687500080625397e-307

    1. Initial program 8.5

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

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

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

    if 2.0687500080625397e-307 < b < 1.756312982163782e+91

    1. Initial program 32.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 flip-+32.2

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

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

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

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

      \[\leadsto \frac{4 \cdot \left(c \cdot a\right)}{\color{blue}{1 \cdot \left(\left(2 \cdot a\right) \cdot \left(\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right)\right)}}\]
    9. Applied *-un-lft-identity20.3

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

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

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

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

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

    if 1.756312982163782e+91 < b

    1. Initial program 58.5

      \[\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{c}{b}}\]
    3. Simplified2.6

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -4.0906093545612224 \cdot 10^{+106}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \le 2.0687500080625397 \cdot 10^{-307}:\\ \;\;\;\;\frac{\sqrt{(\left(c \cdot a\right) \cdot -4 + \left(b \cdot b\right))_*} + \left(-b\right)}{a \cdot 2}\\ \mathbf{elif}\;b \le 1.756312982163782 \cdot 10^{+91}:\\ \;\;\;\;\frac{c \cdot 2}{\left(-b\right) - \sqrt{(\left(c \cdot a\right) \cdot -4 + \left(b \cdot b\right))_*}}\\ \mathbf{else}:\\ \;\;\;\;-\frac{c}{b}\\ \end{array}\]

Reproduce

herbie shell --seed 2019072 +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)))