Average Error: 33.0 → 9.2
Time: 49.7s
Precision: 64
Internal Precision: 3392
\[\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.7038881888823536 \cdot 10^{+149}:\\ \;\;\;\;\frac{-2 \cdot \frac{a \cdot c}{b}}{a \cdot 2}\\ \mathbf{elif}\;b \le -4.719612806782717 \cdot 10^{-281}:\\ \;\;\;\;\frac{4 \cdot c}{(2 \cdot \left(\sqrt{(-4 \cdot \left(a \cdot c\right) + \left(b \cdot b\right))_*}\right) + \left(-2 \cdot b\right))_*}\\ \mathbf{elif}\;b \le 4.546772616322934 \cdot 10^{+41}:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{(b \cdot b + \left(-4 \cdot \left(a \cdot c\right)\right))_*}}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\frac{-b}{a}\\ \end{array}\]

Error

Bits error versus a

Bits error versus b

Bits error versus c

Target

Original33.0
Target20.6
Herbie9.2
\[\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.7038881888823536e+149

    1. Initial program 62.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 fma-neg62.2

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

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

    if -1.7038881888823536e+149 < b < -4.719612806782717e-281

    1. Initial program 34.4

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

      \[\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/38.3

      \[\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. Simplified19.0

      \[\leadsto \frac{\color{blue}{\left(c \cdot 4\right) \cdot a}}{\left(2 \cdot a\right) \cdot \left(\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}\right)}\]
    6. Using strategy rm
    7. Applied associate-/l*14.6

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

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

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

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

    if -4.719612806782717e-281 < b < 4.546772616322934e+41

    1. Initial program 10.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 fma-neg10.5

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

    if 4.546772616322934e+41 < b

    1. Initial program 34.0

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

      \[\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/60.5

      \[\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. Simplified60.7

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

      \[\leadsto \color{blue}{-1 \cdot \frac{b}{a}}\]
    7. Simplified5.6

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -1.7038881888823536 \cdot 10^{+149}:\\ \;\;\;\;\frac{-2 \cdot \frac{a \cdot c}{b}}{a \cdot 2}\\ \mathbf{elif}\;b \le -4.719612806782717 \cdot 10^{-281}:\\ \;\;\;\;\frac{4 \cdot c}{(2 \cdot \left(\sqrt{(-4 \cdot \left(a \cdot c\right) + \left(b \cdot b\right))_*}\right) + \left(-2 \cdot b\right))_*}\\ \mathbf{elif}\;b \le 4.546772616322934 \cdot 10^{+41}:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{(b \cdot b + \left(-4 \cdot \left(a \cdot c\right)\right))_*}}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\frac{-b}{a}\\ \end{array}\]

Runtime

Time bar (total: 49.7s)Debug logProfile

herbie shell --seed 2018250 +o rules:numerics
(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)))