Average Error: 33.2 → 6.8
Time: 1.7m
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 -3.6001997150533654 \cdot 10^{+84}:\\ \;\;\;\;\frac{-c}{b}\\ \mathbf{if}\;b \le -6.488467728451246 \cdot 10^{-240}:\\ \;\;\;\;\frac{1}{\left(\frac{2}{c} \cdot \frac{1}{4}\right) \cdot \left(\left(-b\right) + \sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4}\right)}\\ \mathbf{if}\;b \le 1.1779074516142094 \cdot 10^{+154}:\\ \;\;\;\;\frac{-b}{a \cdot 2} - \frac{\sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4}}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{a \cdot 2}{\frac{b}{c}} - \left(b + b\right)}{a \cdot 2}\\ \end{array}\]

Error

Bits error versus a

Bits error versus b

Bits error versus c

Target

Original33.2
Target20.7
Herbie6.8
\[\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 < -3.6001997150533654e+84

    1. Initial program 57.3

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

      \[\leadsto \frac{\left(-b\right) - \color{blue}{\left(2 \cdot \frac{c \cdot a}{b} - b\right)}}{2 \cdot a}\]
    3. Applied simplify3.2

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

    if -3.6001997150533654e+84 < b < -6.488467728451246e-240

    1. Initial program 33.1

      \[\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-num33.1

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

      \[\leadsto \frac{1}{\frac{2 \cdot a}{\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)}}}}}\]
    6. Applied associate-/r/33.3

      \[\leadsto \frac{1}{\color{blue}{\frac{2 \cdot a}{\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)}} \cdot \left(\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}\right)}}\]
    7. Applied simplify7.9

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

    if -6.488467728451246e-240 < b < 1.1779074516142094e+154

    1. Initial program 9.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-sub9.8

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

    if 1.1779074516142094e+154 < b

    1. Initial program 60.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 clear-num60.9

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

      \[\leadsto \frac{1}{\frac{2 \cdot a}{\left(-b\right) - \color{blue}{\left(b - 2 \cdot \frac{c \cdot a}{b}\right)}}}\]
    5. Applied simplify2.3

      \[\leadsto \color{blue}{\frac{\frac{a \cdot 2}{\frac{b}{c}} - \left(b + b\right)}{a \cdot 2}}\]
  3. Recombined 4 regimes into one program.
  4. Applied simplify6.8

    \[\leadsto \color{blue}{\begin{array}{l} \mathbf{if}\;b \le -3.6001997150533654 \cdot 10^{+84}:\\ \;\;\;\;\frac{-c}{b}\\ \mathbf{if}\;b \le -6.488467728451246 \cdot 10^{-240}:\\ \;\;\;\;\frac{1}{\left(\frac{2}{c} \cdot \frac{1}{4}\right) \cdot \left(\left(-b\right) + \sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4}\right)}\\ \mathbf{if}\;b \le 1.1779074516142094 \cdot 10^{+154}:\\ \;\;\;\;\frac{-b}{a \cdot 2} - \frac{\sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4}}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{a \cdot 2}{\frac{b}{c}} - \left(b + b\right)}{a \cdot 2}\\ \end{array}}\]

Runtime

Time bar (total: 1.7m)Debug logProfile

herbie shell --seed '#(1071501266 3581234924 1086666455 2685055582 1243441566 1802958749)' 
(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)))