Average Error: 35.0 → 6.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 -1.30711257927562294 \cdot 10^{54}:\\ \;\;\;\;-1 \cdot \frac{c}{b}\\ \mathbf{elif}\;b \le 1.10816957325862603 \cdot 10^{-243}:\\ \;\;\;\;{\left(\frac{2 \cdot c}{\sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)} - b}\right)}^{1}\\ \mathbf{elif}\;b \le 2.3651486002630512 \cdot 10^{104}:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\\ \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

Original35.0
Target21.3
Herbie6.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 < -1.30711257927562294e54

    1. Initial program 57.8

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

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

    if -1.30711257927562294e54 < b < 1.10816957325862603e-243

    1. Initial program 28.8

      \[\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-inv28.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--29.0

      \[\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. Simplified17.5

      \[\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. Simplified17.5

      \[\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}\]
    8. Using strategy rm
    9. Applied pow117.5

      \[\leadsto \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 \color{blue}{{\left(\frac{1}{2 \cdot a}\right)}^{1}}\]
    10. Applied pow117.5

      \[\leadsto \color{blue}{{\left(\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}\right)}^{1}} \cdot {\left(\frac{1}{2 \cdot a}\right)}^{1}\]
    11. Applied pow-prod-down17.5

      \[\leadsto \color{blue}{{\left(\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}\right)}^{1}}\]
    12. Simplified17.0

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

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

    if 1.10816957325862603e-243 < b < 2.3651486002630512e104

    1. Initial program 7.8

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

    if 2.3651486002630512e104 < b

    1. Initial program 48.5

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -1.30711257927562294 \cdot 10^{54}:\\ \;\;\;\;-1 \cdot \frac{c}{b}\\ \mathbf{elif}\;b \le 1.10816957325862603 \cdot 10^{-243}:\\ \;\;\;\;{\left(\frac{2 \cdot c}{\sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)} - b}\right)}^{1}\\ \mathbf{elif}\;b \le 2.3651486002630512 \cdot 10^{104}:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \end{array}\]

Reproduce

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