Average Error: 33.4 → 9.1
Time: 27.5s
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(c \cdot 4\right) \cdot a}{a \cdot \left(\sqrt{b \cdot b - \left(c \cdot 4\right) \cdot a} + \left(-b\right)\right)} \cdot \frac{1}{2}\\ \mathbf{elif}\;b \le 2.696518439055105 \cdot 10^{+143}:\\ \;\;\;\;\frac{1}{2} \cdot \frac{\left(-b\right) - \sqrt{b \cdot b - \left(c \cdot 4\right) \cdot 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.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 *-un-lft-identity39.2

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

      \[\leadsto \frac{\color{blue}{1 \cdot \left(-b\right)} - 1 \cdot \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
    5. Applied distribute-lft-out--39.2

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

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

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

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

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

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

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

      \[\leadsto \frac{1}{2} \cdot \frac{\color{blue}{\left(4 \cdot c\right) \cdot a}}{a \cdot \left(\left(-b\right) + \sqrt{b \cdot b - a \cdot \left(4 \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 *-un-lft-identity11.6

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

      \[\leadsto \frac{\color{blue}{1 \cdot \left(-b\right)} - 1 \cdot \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
    5. Applied distribute-lft-out--11.6

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

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

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

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

      \[\leadsto \frac{1}{2} \cdot \frac{\left(-b\right) - \sqrt{\color{blue}{b \cdot b - a \cdot \left(4 \cdot c\right)}}}{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. Taylor expanded around inf 1.7

      \[\leadsto \color{blue}{\frac{c}{b} - \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(c \cdot 4\right) \cdot a}{a \cdot \left(\sqrt{b \cdot b - \left(c \cdot 4\right) \cdot a} + \left(-b\right)\right)} \cdot \frac{1}{2}\\ \mathbf{elif}\;b \le 2.696518439055105 \cdot 10^{+143}:\\ \;\;\;\;\frac{1}{2} \cdot \frac{\left(-b\right) - \sqrt{b \cdot b - \left(c \cdot 4\right) \cdot a}}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \end{array}\]

Reproduce

herbie shell --seed 2019053 
(FPCore (a b c)
  :name "quadm (p42, negative)"

  :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)))