Average Error: 33.4 → 9.1
Time: 26.4s
Precision: 64
Internal Precision: 128
\[\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 -1.6964169257649298 \cdot 10^{+81}:\\ \;\;\;\;-\frac{c}{b}\\ \mathbf{elif}\;b \le -2.650832923705524 \cdot 10^{-105}:\\ \;\;\;\;\frac{\left(a \cdot c\right) \cdot 4}{\left(2 \cdot a\right) \cdot \left(\sqrt{b \cdot b - \left(a \cdot c\right) \cdot 4} + \left(-b\right)\right)}\\ \mathbf{elif}\;b \le 2.696518439055105 \cdot 10^{+143}:\\ \;\;\;\;\frac{1}{a} \cdot \frac{\left(-b\right) - \sqrt{b \cdot b - \left(a \cdot c\right) \cdot 4}}{2}\\ \mathbf{else}:\\ \;\;\;\;-\frac{b}{a}\\ \end{array}\]

Error

Bits error versus a

Bits error versus b

Bits error versus c

Target

Original33.4
Target20.8
Herbie9.1
\[\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 < -1.6964169257649298e+81

    1. Initial program 57.5

      \[\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{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}}\]

    if -1.6964169257649298e+81 < b < -2.650832923705524e-105

    1. Initial program 39.2

      \[\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--39.3

      \[\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 associate-/l/42.6

      \[\leadsto \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(2 \cdot a\right) \cdot \left(\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}\right)}}\]
    5. Simplified17.7

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

    if -2.650832923705524e-105 < b < 2.696518439055105e+143

    1. Initial program 11.6

      \[\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
    2. Using strategy rm
    3. Applied associate-/r*11.5

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

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

    if 2.696518439055105e+143 < b

    1. Initial program 56.7

      \[\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
    2. Using strategy rm
    3. Applied associate-/r*56.7

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

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

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

      \[\leadsto \color{blue}{-1 \cdot \frac{b}{a}}\]
    8. Simplified1.9

      \[\leadsto \color{blue}{-\frac{b}{a}}\]
  3. Recombined 4 regimes into one program.
  4. Final simplification9.1

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -1.6964169257649298 \cdot 10^{+81}:\\ \;\;\;\;-\frac{c}{b}\\ \mathbf{elif}\;b \le -2.650832923705524 \cdot 10^{-105}:\\ \;\;\;\;\frac{\left(a \cdot c\right) \cdot 4}{\left(2 \cdot a\right) \cdot \left(\sqrt{b \cdot b - \left(a \cdot c\right) \cdot 4} + \left(-b\right)\right)}\\ \mathbf{elif}\;b \le 2.696518439055105 \cdot 10^{+143}:\\ \;\;\;\;\frac{1}{a} \cdot \frac{\left(-b\right) - \sqrt{b \cdot b - \left(a \cdot c\right) \cdot 4}}{2}\\ \mathbf{else}:\\ \;\;\;\;-\frac{b}{a}\\ \end{array}\]

Reproduce

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