Average Error: 34.5 → 8.9
Time: 4.9s
Precision: binary64
\[\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 -9.95875112885693445 \cdot 10^{42}:\\ \;\;\;\;-1 \cdot \frac{c}{b}\\ \mathbf{elif}\;b \le -1.3145521691088466 \cdot 10^{-129}:\\ \;\;\;\;\frac{0 + 1 \cdot \left(4 \cdot \left(a \cdot c\right)\right)}{\sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)} - b} \cdot \frac{1}{2 \cdot a}\\ \mathbf{elif}\;b \le 3.54118124572884401 \cdot 10^{123}:\\ \;\;\;\;\frac{1}{\frac{2 \cdot a}{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}}\\ \mathbf{else}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \end{array}\]

Error

Bits error versus a

Bits error versus b

Bits error versus c

Target

Original34.5
Target21.7
Herbie8.9
\[\begin{array}{l} \mathbf{if}\;b \lt 0.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 < -9.95875112885693445e42

    1. Initial program 56.6

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

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

    if -9.95875112885693445e42 < b < -1.3145521691088466e-129

    1. Initial program 36.9

      \[\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
    2. Using strategy rm
    3. Applied div-inv36.9

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

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

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

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

    if -1.3145521691088466e-129 < b < 3.54118124572884401e123

    1. Initial program 11.5

      \[\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
    2. Using strategy rm
    3. Applied clear-num11.7

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

    if 3.54118124572884401e123 < b

    1. Initial program 54.6

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

      \[\leadsto \color{blue}{1 \cdot \frac{c}{b} - 1 \cdot \frac{b}{a}}\]
    3. Simplified3.6

      \[\leadsto \color{blue}{1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)}\]
  3. Recombined 4 regimes into one program.
  4. Final simplification8.9

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -9.95875112885693445 \cdot 10^{42}:\\ \;\;\;\;-1 \cdot \frac{c}{b}\\ \mathbf{elif}\;b \le -1.3145521691088466 \cdot 10^{-129}:\\ \;\;\;\;\frac{0 + 1 \cdot \left(4 \cdot \left(a \cdot c\right)\right)}{\sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)} - b} \cdot \frac{1}{2 \cdot a}\\ \mathbf{elif}\;b \le 3.54118124572884401 \cdot 10^{123}:\\ \;\;\;\;\frac{1}{\frac{2 \cdot a}{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}}\\ \mathbf{else}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \end{array}\]

Reproduce

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

  :herbie-target
  (if (< b 0.0) (/ c (* a (/ (+ (neg b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))) (/ (- (neg b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))

  (/ (- (neg b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))